﻿//localStorage,
var arrLayerIndex = new Array();
var virtualPath=getVirtualPath();
String.prototype.querystring = function(name){var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)","i"),r; if (r=this.match(reg)){return r[2]; }return ""; };
var _elements = document.getElementsByTagName('script');
var _element=_elements[_elements.length-1];
var _src=_element.getAttribute("src");
var _ver=_src.querystring("ver");

/*基础*/

document.write('<script src="' + virtualPath + 'Scripts/jquery.js"></script>');
document.write('<script src="' + virtualPath + 'Scripts/eketeam.js?ver=' + _ver + '"></script>');


//if(navigator.userAgent.toLowerCase().indexOf("msie")>0) 
if(window.attachEvent)
{
	document.write('<script src="' + virtualPath + 'Scripts/ajaxfileupload.js"><\/script>');
} 
﻿document.write('<script src="' + virtualPath + 'Plugins/eControls/eControls.js?ver=' + _ver + '"></script>');
/*移动端日期控件*/
document.write('<script src="' + virtualPath + 'Scripts/rolldate.min.js"></script>');
/*kindeditor星级控件*/
document.write('<script src="' + virtualPath + 'Scripts/jquery.raty.min.js"></script>');
/*layui*/
﻿document.write('<script src="' + virtualPath + 'Plugins/layui226/layui.all.js"></script>');
/*AntV报表*/
﻿document.write('<script src="' + virtualPath + 'Plugins/AntV/g2.min.js"></script>');
document.write('<script src="' + virtualPath + 'Plugins/AntV/data-set.min.js"></script>');
/*kindeditor编辑器*/
﻿document.write('<script src="' + virtualPath + 'Plugins/kindeditor351/kindeditor.js"><\/script>');
/*百度编辑器*/
//document.write('<script src="' + virtualPath + 'Plugins/ueditor1.4.3.3/ueditor.config.js"><\/script>');
//document.write('<script src="' + virtualPath + 'Plugins/ueditor1.4.3.3/ueditor.all.min.js"><\/script>');
//document.write('<script src="' + virtualPath + 'Plugins/ueditor1.4.3.3/lang/zh-cn/zh-cn.js"><\/script>');


﻿document.write('<script src="' + virtualPath + 'Plugins/ace/ace.js"></script>');
document.write('<script src="' + virtualPath + 'Plugins/ace/ext-language_tools.js"></script>');



function getVirtualPath()
{
	var elements = document.getElementsByTagName('script');
	var element=elements[elements.length-1];
	var src=element.getAttribute("src");
	if(src.toLowerCase().indexOf("http")>-1)
	{
		var i= src.toLowerCase().indexOf("/scripts/");
		if(i>0)
		{
			return src.substring(0,i+1);
		}
	}
	//if(src.startsWith("/")){return "/"};
	if(src.indexOf("/")==0){return "/"};
	var virtualPath="";
	if(src.indexOf("../")>-1)
	{
		for(var i=0;i<src.match(/\.\.\//ig).length;i++)
		{
			virtualPath+="../";
		}
	}
	return virtualPath;
};
var lastpictureobjid=null;
function openPictureEditor(obj,lastobjid)
{	
	//lastpictureobj=$(obj).siblings("img");
	lastpictureobjid=lastobjid;
	var url = virtualPath + "Plugins/pictureeditor/index.html";
	layer.open({
		type: 2,
		skin: 'layui-layer-rim', //加上边框
        title: '在线编辑图片',
        maxmin: false,
        shadeClose: true, //点击遮罩关闭层
		area:['90%','98%'],
        content: [url,'no'], 
        success: function (layero, index) { arrLayerIndex.push(index); },
        cancel: function (index, layero) { arrLayerIndex.pop(); },
        end: function (index) { arrLayerIndex.pop(); }
    });	
};
function execMethod(obj)
{
	var url = virtualPath + "Plugins/Reflection.aspx";
	var data={};
	$.ajax({
		type: "post",
		async: false,
		data:obj,
        url:url,
        dataType: "json",
        success: function (_data)
		{
			data=_data;
        }
    });
	return data;
};
function saveStream(stream)
{
	//alert(typeof(stream));
	var url = virtualPath + "Plugins/ProUpload.aspx?type=image";
	//if($(obj).parent().attr("MaxWidth").length>1) {url+="&PictureMaxWidth=" + $(obj).parent().attr("MaxWidth");}
	var formData = new FormData();
	formData.append('files', stream,"aaa.png");
	$.ajax({
		type: "post", 
		async: false,
		data:formData,
        url:url,
        dataType: "json",
		contentType: false,
		cache: false,//上传文件无需缓存
        processData: false,//用于对data参数进行序列化处理 这里必须false
        success: function (data)
		{
			//alert(JSON.stringify(data));
			if(data.errcode=="0")
			{
				var box=$("#" + lastpictureobjid + "_box");				
				if(data.files.length>0)
				{
					$("#" + lastpictureobjid).val(data.files[0].url);
					box.find("img").attr("src",data.files[0].url);
					if(box.find("iframe").length>0)
					{
						var _url=box.find("iframe").attr("src");
						_url=_url.addquerystring("act","finsh");
						_url=_url.addquerystring("file",data.files[0].url);
						box.find("iframe").attr("src",_url);

					}
					//lastpictureobj.siblings("input").val(data.files[0].url);
					//lastpictureobj.attr("src",data.files[0].url);
					//$("#" + $(obj).attr("id").replace("_file","")).val(data.files[0].url);
					
				}
				lastpictureobjid=null;
				layer.close(arrLayerIndex.pop());
			}
			else
			{
				layer.msg(data.message);
			}
			//
			//
			/*
			layer.msg(data.message);
			obj.value="";
			var callback=$(obj).attr("callback");
			if(callback)
			{
				//eval("if(typeof(" + callback + ")=='function'){" + callback + "(" + data.files +  ");}");
				if(data.files)
				{
					eval(callback + "(data.files);");
				}
				else
				{
					eval(callback + "(data);");
				}
			}
			*/
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {}
    });
};
function getWeChatShareData(area)
{
	var url = virtualPath + "Plugins/Tencent/WeChat/getShareData.aspx";
	if(area){url+="?area=" + area;}
	var data=[];
	$.ajax({
		type: "get",
		async: false,
		url: url,
		dataType: "json",
		success: function(_data)
		{
			data=_data.data;
		}
	});
	return data;
};
function WeChatScanQRCode(obj,callback)
{
	if(!window.wx){return;}
	var data=getWeChatShareData();
	if(data.length==0){return;}
	var acc=data[0];
	wx.config({
		debug: false,
		beta: true,
		appId: acc.appid,
		timestamp: parseInt(acc.timestamp),
		nonceStr: acc.noncestr,
		signature: acc.signature,
		jsApiList: ['checkJsApi','scanQRCode'],
		complete:function(ret)
		{
            //alert("wx.config.complete:" + JSON.stringify(ret))
        }
    });
	 wx.error(function (res) {
    	//alert("出错了：" + res.errMsg);//这个地方的好处就是wx.config配置错误，会弹出窗口哪里错误，然后根据微信文档查询即可。
		//alert(JSON.stringify(res));
	 });
	
	wx.ready(function () 
    {
		/*
		wx.checkJsApi({
		  jsApiList: ['scanQRCode'],
		  success: function (res) {
			alert(JSON.stringify(res));
		  }
		});
		*/		
		wx.scanQRCode({needResult:1,scanType: ["qrCode","barCode"],
                success:function(res){
                   // alert(res.resultStr);//alert(JSON.stringify(res));
				   	var arr=res.resultStr.split(",");
					var code=arr.length==1?arr[0]:arr[1]; 
					if(obj){$("#"+obj).val(code);}
					if(typeof(callback)=="function"){callback(code);};
                },
				error:function(res){
					//alert(JSON.stringify(res));
			  	}
        });
		//wx.scanQRCode({needResult:1,desc:"scanQRCode desc",success:function(e){alert(JSON.stringify(e))}});//自己处理
	});
};
function getWxWorkShareData(area)
{
	var url = virtualPath + "Plugins/Tencent/WxWork/getShareData.aspx";
	if(area){url+="?area=" + area;}
	var data=[];
	$.ajax({
		type: "get",
		async: false,
		url: url,
		dataType: "json",
		success: function(_data)
		{
			data=_data.data;
		}
	});
	return data;
};
function WxWorkScanQRCode(obj,callback)
{
	if(!window.wx){return;}
	var data=getWxWorkShareData();
	if(data.length==0){return;}
	var acc=data[0];
	wx.config({
		debug: false,
		beta: true,
		appId: acc.appid,
		timestamp: parseInt(acc.timestamp),
		nonceStr: acc.noncestr,
		signature: acc.signature,
		jsApiList: ['checkJsApi','scanQRCode'],
		complete:function(ret)
		{
            //alert("wx.config.complete:" + JSON.stringify(ret))
        }
    });
	 wx.error(function (res) {
    	//alert("出错了：" + res.errMsg);//这个地方的好处就是wx.config配置错误，会弹出窗口哪里错误，然后根据微信文档查询即可。
		//alert(JSON.stringify(res));
	 });
	
	wx.ready(function () 
    {
		/*
		wx.checkJsApi({
		  jsApiList: ['scanQRCode'],
		  success: function (res) {
			alert(JSON.stringify(res));
		  }
		});
		*/		
		wx.scanQRCode({needResult:1,desc:"scanQRCode desc",
                success:function(res){
                   // alert(res.resultStr);//alert(JSON.stringify(res));
				   	var arr=res.resultStr.split(",");
					var code=arr.length==1?arr[0]:arr[1]; 
					if(obj){$("#"+obj).val(code);}
					if(typeof(callback)=="function"){callback(code);};
                },
				error:function(res){
					//alert(JSON.stringify(res));
			  	}
        });
		//wx.scanQRCode({needResult:1,desc:"scanQRCode desc",success:function(e){alert(JSON.stringify(e))}});//自己处理
	});
};
//调用企业微信扫一扫
function openWxWorkScanQRCode(obj,callback) //未启用
{
	if(!IsMobile())return;
	var url = virtualPath + "Plugins/Tencent/WxWork/scanQRCode.aspx?act=get";
	if(obj){url+="&obj="+ obj;}	
	if(callback){url+="&callback="+ callback;}
	//url+="&fromurl="+  encodeURIComponent(document.location.href.split("?")[0]);
	url+="&fromurl="+  encodeURIComponent(document.location.href);
	layer.open({
		type: 2,
		skin: 'layui-layer-rim', //加上边框
        title: '扫一扫',
        maxmin: false,
        shadeClose: true, //点击遮罩关闭层
		area:['180px','100px'],
        content: [url,'no'], 
        success: function (layero, index) { arrLayerIndex.push(index); },
        cancel: function (index, layero) { arrLayerIndex.pop(); },
        end: function (index) { arrLayerIndex.pop(); }
    });	
};
function scanQRCode_callback(result)//未启用
{	
	layer.close(arrLayerIndex.pop());
};
function saveCounterSign(UserArea,itemid,pid)
{
	var url = virtualPath + "Plugins/counterSign.aspx?";
	if(typeof(AppItem)=="string" && AppItem.length > 0){url+="AppItem=" + AppItem + "&";}
	if(typeof(ModelID)=="string" && ModelID.length > 0){url+="ModelID=" + ModelID + "&";}
	url+="UserArea=" + UserArea;
	url+="&itemid=" + itemid;
	url+="&pid=" + pid;
	url+="&id=" + document.location.href.getquerystring("id");	
	var data = eSignIn.getdata();
	$.ajax({
        type: 'POST',
		async: false,
        url: url,
		//data: '{ "imageData" : "' + data + '" }',
		data: {"imageData" :  data  },
        //contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (data) {
			parent.layer.msg(data.message);
			if(data.errcode=="0")
			{			
				var html='';				
				$.each(data.data, function()
				{
					html+='<img src="'+ this["url"] +'" style="max-width:100px;max-height:30px;border:0;">'; 
				});
				$("#"+pid+"_box",parent.document).html(html);
				parent.layer.close(parent.arrLayerIndex.pop());
			}
        }
    });
};
function counterSign(UserArea,itemid,pid)
{
	var url = virtualPath + "Plugins/counterSign.aspx?";
	if(typeof(AppItem)=="string" && AppItem.length > 0){url+="AppItem=" + AppItem + "&";}
	if(typeof(ModelID)=="string" && ModelID.length > 0){url+="ModelID=" + ModelID + "&";}	
	url+="UserArea=" + UserArea;
	url+="&itemid=" + itemid;
	url+="&pid=" + pid;
	url+="&id=" + document.location.href.getquerystring("id");
	layer.open({
		type: 2,
		skin: 'layui-layer-rim', //加上边框
        title: '签名',
        maxmin: false,
        shadeClose: true, //点击遮罩关闭层
        //area: ['600px', '500px'],
		area:IsMobile() ? ['100%','280px'] : ["390px" , "280px"],
        content: [url,'no'], 
        success: function (layero, index) { arrLayerIndex.push(index); },
        cancel: function (index, layero) { arrLayerIndex.pop(); },
        end: function (index) { arrLayerIndex.pop(); }
    });	
};
function saveSignIn()
{
	var url = virtualPath + "Plugins/SignIn.aspx?";
	if(typeof(AppItem)=="string" && AppItem.length > 0){url+="AppItem=" + AppItem + "&";}
	if(typeof(ModelID)=="string" && ModelID.length > 0){url+="ModelID=" + ModelID + "&";}
	url+="id=" + document.location.href.getquerystring("id");	
	var data = eSignIn.getdata();
 	$.ajax({
        type: 'POST',
		async: false,
        url: url,
		//data: '{ "imageData" : "' + data + '" }',
		data: {"imageData" :  data  },
        //contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (data) {
			layer.msg(data.message);
			if(data.errcode=="0")
			{
				var dd=$("#esignin").parent();
				dd.html('<img src="../' + data.signfile +  '">');
			}
        }
    });
};
function delFromLink(obj,id)
{
	 //layer.msg('请输入金额', {icon: 2});
	var evt = event || window.event;
    if (evt.stopPropagation) { evt.stopPropagation(); } else { evt.cancelBubble = true; }
    if (evt.preventDefault) { evt.preventDefault(); } else { evt.cancelBubble = true; }
	
	var input=$("#" + id);
	var index=$(obj).parent().index();	
	layer.confirm('', {btn: ['确定', '取消'], title: "确认要删除吗?",shadeClose: true}, function (idx, layero) {
		var model=input.val().toJson();
		//model.Convert=true;
		model.remove(index);
		input.val(model.toJson());
		$(obj).parent().remove();
		layer.close(idx);
    });	
	//_model.remove(index);	
	//var data=model.get(index);	
	//input.value=model.toJson();	
};
function editFromLink(obj,id)
{
	var index=$(obj).index();
	var input=$("#" + id);	
	var model=input.val().toJson();
	//model.Convert=true;	
	var data=model.get(index);
	
	//alert(data.toJson() + "::" + data.name);
	
	
	//document.title=index;
	//layer.msg(index);
	
	layer.open({
    type: 1 //Page层类型
	,title: "修改连接"
	,skin: 'layui-layer-prompt'
	,shadeClose: true
    ,btn:["确定","取消"]	
    ,area : ["400px" , "260px"]  
    ,content: '<div>地址：<input id="url" type="text" class="layui-layer-input" value="' + data.url + '" onblur="flinkblur(this);" placeholder="连接地址">名称：<input style="margin-top:10px;" id="name" type="text" class="layui-layer-input" value="' +  data.name + '" placeholder="连接名称"></div>'
    ,yes: function(index, layero){
		data["url"]=$(layero).find("#url").val();
		data["name"]= $(layero).find("#name").val();
		input.val(model.toJson());
		$(obj).html($(layero).find("#name").val() + '<a href="javascript:;" class="del" onclick="delFromLink(this,\'' + id + '\');">&nbsp;</a>');
		layer.close(index);
	}
	});
		
};

function getHtmlTitle(url)
{
	var title="";
	$.ajax({
			type: 'post',
			async: false,
			url:  virtualPath + 'Plugins/getTitle.ashx',	
			data:{url:url},
			dataType: "json",
			success: function(data)
			{
				if(data.errcode=="0")
				{
					//alert(JSON.stringify(data));
					title=data.title;
				}
			}
	});	
	
	return title;
};
function flinkblur(obj)
{
	var txt=$(obj).parent().find("input:eq(1)");
	if(txt.val().length>0){return;}

	var url=$(obj).val();
	if(url.toLowerCase().indexOf("http")==0)
	{
		var title=getHtmlTitle(url);
		txt.val(title);
	}
	//alert(url.toLowerCase().indexOf("http"));
};
function addFromLink(obj,id)
{
	//var url="http://www.eketeam.com/";
	//var title=getHtmlTitle(url);
	//alert(title);
	//return;
	var input=$("#" + id);
	var ol=$(obj).parent().find("ol");
	layer.open({
    type: 1 //Page层类型
	,title: "添加连接"
	,skin: 'layui-layer-prompt'
	,shadeClose: true
    ,btn:["确定","取消"]	
   	,area : ["400px" , "260px"]  
    ,content: '<div>地址：<input id="url" type="text" class="layui-layer-input" value="" onblur="flinkblur(this);" placeholder="连接地址">名称：<input style="margin-top:10px;" id="name" type="text" class="layui-layer-input" value="" placeholder="连接名称"></div>'
    ,yes: function(index, layero){
		//为空判断
		var model=input.val().toJson();
		//model.Convert=true;	
		var data=new Object();
		data["url"]=$(layero).find("#url").val();
		data["name"]= $(layero).find("#name").val();
	
		ol.append('<li onclick="editFromLink(this,\'' + id + '\');">' + $(layero).find("#name").val() + '<a href="javascript:;" class="del" onclick="delFromLink(this,\'' + id + '\');">&nbsp;</a></li>');	
		
		model.append(data);	
		input.val(model.toJson());
		layer.close(index);
	  
    }
});
	
};
//文件查看
function viewFile(path,width,height)
{
	if(path.toLowerCase().indexOf("upload/")>0){path=path.substring(path.toLowerCase().indexOf("upload/"));}
	var _width=typeof(width)=="undefined" ? "80%" : width;
	var _height=typeof(height)=="undefined" ? "80%" : height;	
	if(path.indexOf(".mp3")>-1)
	{
		_width="360px";
		_height="160px";
	}
	if(path.indexOf(".mp4")>-1)
	{
		if(IsMobile())
		{
			_width="90%";
			_height="360px";
		}
		else
		{
			_width="680px";
			_height="560px";
		}
	}
	var url = virtualPath + "Plugins/viewFile/default.aspx?path=" + path;
    layer.open({
      type: 2,
      title: "文件预览",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
      area : [_width,_height],
	  // content: [url,'no'], 
	  content: url,
	  success: function(layero, index){},
	  cancel: function(index, layero){},
	  end : function(index){}
    });	
};
//人员选择
var UserSelectParent;
function openUserSelect(obj,controlid)
{	
	var vpath=obj.getAttribute("vpath");
	UserSelectParent=$(obj).parent().parent();
	var url=(vpath == null ? virtualPath : vpath) + "Plugins/UserSelect.aspx?obj=" + controlid + "&t=" + now();
	layer.open({
		type: 2,
		skin: 'layui-layer-rim', //加上边框
        title: '人员选择',
        maxmin: false,
        shadeClose: true, //点击遮罩关闭层
        //area: ['600px', '500px'],
		area:IsMobile() ? ['95%','95%'] : ["600px" , "500px"],    
        content: url,
        success: function (layero, index) { arrLayerIndex.push(index); },
        cancel: function (index, layero) { arrLayerIndex.pop(); },
        end: function (index) { arrLayerIndex.pop(); }
    });	
};
function openDepartmentSelect(obj,controlid)
{
	var vpath=obj.getAttribute("vpath");
	UserSelectParent=$(obj).parent().parent();
	var url=(vpath == null ? virtualPath : vpath) + "Plugins/DepartmentSelect.aspx?obj=" + controlid + "&t=" + now();
	layer.open({
		type: 2,
		skin: 'layui-layer-rim', //加上边框
        title: '部门选择',
        maxmin: false,
        shadeClose: true, //点击遮罩关闭层
        //area: ['600px', '500px'],
		area:IsMobile() ? ['95%','95%'] : ["600px" , "500px"],    
        content: url,
        success: function (layero, index) { arrLayerIndex.push(index); },
        cancel: function (index, layero) { arrLayerIndex.pop(); },
        end: function (index) { arrLayerIndex.pop(); }
    });	
	
};



function getRndCode(picid)
{
	document.getElementById(picid).src = virtualPath + "Plugins/RndPic.aspx?t=" + now();
};
//自定义导入程序
function custom_import(title,url)
{
        layer.open({
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            title: title,
            maxmin: false,
            shadeClose: true, //点击遮罩关闭层
            area: ['400px', '300px'],
            content: url,
            success: function (layero, index) { arrLayerIndex.push(index); },
            cancel: function (index, layero) { arrLayerIndex.pop(); },
            end: function (index) { arrLayerIndex.pop();document.location.assign(document.location.href); }
        });
};
//显示自定义项
function check_InputValue(obj)
{
	var span=$(obj).parent();	
	
	if(span.find("input[inputvalue]").length>0)
	{
		var value=span.find("input[inputvalue]").attr("inputvalue");
		if(obj.tagName=="SELECT")
		{
			//alert($(obj).val());
			if(value==$(obj).val())
			{
				span.find("input[inputvalue]").show();
			}
			else
			{
				span.find("input[inputvalue]").hide();
			}
			return;
		}
		if(span.find("input[value='" + value + "']:checked").length==1)
		{
			span.find("input[inputvalue]").show();
		}
		else
		{
			span.find("input[inputvalue]").hide();
		}
	}
};
//列表选择
//表头全选事件
function getSelectIDS()
{
	var sels=$("input[name='selitem']:checked");
	if(sels.length==0) return "";
	var ids="";
	for(var i=0;i<sels.length;i++)
	{
		if(i>0){ids+=",";}
		ids+=sels[i].value;
	}
	return ids;
};
function selectAllItems(obj)
{
    $("input[name='selitem']").prop("checked", obj.checked);
    selectMore_check();
};
function selectMore_check()
{

	//alert($("input[name='selitem']:checked").length + "::" + $(".selectMore").length );

	
	if($("input[name='selitem']:checked").length==0)
	{
		$("#btn_PrintMore").hide();
		$("#btn_selMore").hide();
		$("#btn_delMore").hide();		
		$(".selectMore").hide();
	}
	else
	{
		$("#btn_PrintMore").show();
		$(".selectMore").show();
		$("#btn_selMore").show();
		var count=0;
		$("input[name='selitem']:checked").each(function(i,elem)
		{			
			count+=$(elem).parents("tr:first").find("a[href*='act=del']").length;
			count+=$(elem).parents("tr:first").find("a[_href*='act=del']").length;
			count+=$(elem).parents("tr:first").find("a[ehref*='act=del']").length;
		});
		if(count==0)
		{
			$("#btn_delMore").hide();
		}
		else
		{
			$("#btn_delMore").show();		
		}
	}
	if(typeof(select_callback)=="function")
	{
		select_callback();
	}		
};
//删除-全选
function selectdelItems(obj)
{
	$("input[name='delitem']").prop("checked",obj.checked);
	deleteMore_check();
};
//是否有可删除项判断
function deleteMore_check()
{
	//alert($("input[name='delitem']:checked").length);
	if($("input[name='delitem']:checked").length==0)
	{
		$("#btn_delMore").hide();
	}
	else
	{
		var count=0;
		$("input[name='delitem']:checked").each(function(i,elem)
		{			
			count+=$(elem).parents("tr:first").find("a[href*='act=del']").length;
			count+=$(elem).parents("tr:first").find("a[_href*='act=del']").length;
			count+=$(elem).parents("tr:first").find("a[ehref*='act=del']").length;
		});
		if(count==0)
		{
			$("#btn_delMore").hide();
		}
		else
		{
			$("#btn_delMore").show();
		}
	}
};
//批量打印
function printMore()
{
	var sels=$("input[name='selitem']:checked");
	if(sels.length==0)
	{
		alert("请选择要对比的数据!");
		return;
	}	
	var ids="";
	for(var i=0;i<sels.length;i++)
	{
		if(i>0){ids+=",";}
		ids+=sels[i].value;
	}
	if(ids.length==0)
	{
		alert("没有符合条件的数据!");
		return;
	}
	var url=document.location.href;
	url+= url.indexOf("?") > -1 ? "&" : "?";
	url+="act=print&id=" + ids;	
	var table=getobj("eDataTable");
	var ajax = parseBool(table.getAttribute("ajax"));
	if(!ajax)
	{
		//document.location.assign(url);
		//return;
	}
	url=url.addquerystring("ajax","true");
	layer.open({
			  type: 2
			  ,title: "打印"	
			  ,shadeClose: true //点击遮罩关闭层
			  //,area: [(rect.right-rect.left) + "px",(rc.bottom-rc.top-rect.top-10) + "px"]
			  //,offset: [rect.top + "px", rect.left + "px"]
			  ,area: ["95%","95%"]
			  ,content: url
			  
			  ,success: function(layero, index)
			  {
				arrLayerIndex.push(index);
			  }
			  ,cancel: function(index, layero)
			  {
				  arrLayerIndex.pop();
			  }				
	});
};
//对比按钮事件
function contrastMore()
{
	var sels=$("input[name='selitem']:checked");
	if(sels.length==0)
	{
		alert("请选择要对比的数据!");
		return;
	}	
	var ids="";
	for(var i=0;i<sels.length;i++)
	{
		if(i>0){ids+=",";}
		ids+=sels[i].value;
	}
	if(ids.length==0)
	{
		alert("没有符合条件的数据!");
		return;
	}
	var url=document.location.href;
	url+= url.indexOf("?") > -1 ? "&" : "?";
	url+="act=view&id=" + ids;	
	var table=getobj("eDataTable");
	var ajax = parseBool(table.getAttribute("ajax"));
	if(!ajax)
	{
		document.location.assign(url);
		return;
	}
	url=url.addquerystring("ajax","true");
	layer.open({
			  type: 2
			  ,title: "对比"	
			  ,shadeClose: true //点击遮罩关闭层
			  //,area: [(rect.right-rect.left) + "px",(rc.bottom-rc.top-rect.top-10) + "px"]
			  //,offset: [rect.top + "px", rect.left + "px"]
			  ,area: ["95%","95%"]
			  ,content: url
			  
			  ,success: function(layero, index)
			  {
				arrLayerIndex.push(index);
			  }
			  ,cancel: function(index, layero)
			  {
				  arrLayerIndex.pop();
			  }				
	});
};
function delrequest(url)
{
	$.ajax({
			type: 'get',
			async: false,
			url: url,	
			dataType: "html",
			success: function(data)
			{
			}
		});
};
//删除所选按钮事件
function deleteMore()
{
	//var sels=$("input[name='delitem']:checked");
	var sels=$("input[name='selitem']:checked");
	if(sels.length==0)
	{
		alert("请选择要删除的数据!");
		return;
	}	
	var ids="";
	/*
	for(var i=0;i<sels.length;i++)
	{
		if(i>0){ids+=",";}
		ids+=sels[i].value;
	}
	*/
	sels.each(function(i,elem)
	{
		if($(elem).parents("tr:first").find("a[href*='act=del']").length > 0 || $(elem).parents("tr:first").find("a[_href*='act=del']").length > 0  || $(elem).parents("tr:first").find("a[ehref*='act=del']").length > 0 )
		{
			if(ids.length>0){ids+=",";}
			ids+=elem.value;
		}		
	});
	if(ids.length==0)
	{
		alert("没有符合条件的数据!");
		return;
	}
	var page=getobj("page");
	//if(page)
	//alert(page.value);
	//return;
	
	
	var allitem=$("input[name='selallitem']:checked").length == 0 ? false : true;
	if(!allitem)
	{
		var _back=confirm('确认要删除所选数据吗？');
		if(!_back){return;}	
		var url=document.location.href;
		//url+= url.indexOf("?") > -1 ? "&" : "?";		
		//url+="act=delmore&ids=" + ids;
		url=url.addquerystring("act","delmore");
		url=url.addquerystring("ids",ids);
		//alert(url);
		//return;
		if(top!=self)//Frame打开
		{
			delrequest(url);
			Search(); 
		}
		else
		{
			document.location.assign(url);
		}		
	}
	else
	{
		layer.confirm('确认要删除吗?', {title: "删除",shadeClose: true, btn: ['删除已选', '删除所有', '取消']},
			function (idx, layero)
			{
				layer.close(idx);
				var url=document.location.href;
				//url+= url.indexOf("?") > -1 ? "&" : "?";
				//url+="act=delmore&ids=" + ids;	
				url=url.addquerystring("act","delmore");
				url=url.addquerystring("ids",ids);
				//alert(url);
		//return;
				if(top!=self)//Frame打开
				{
					delrequest(url);
					Search();
				}
				else
				{
					document.location.assign(url);
				}
				
			},function(idx, layero)
			{
				layer.close(idx);
				var url=document.location.href;
				//url+= url.indexOf("?") > -1 ? "&" : "?";
				//url+="act=delmore";	
				url=url.addquerystring("act","delmore");
				//alert(url);
		//return;
				if(top!=self)//Frame打开
				{
					delrequest(url);
					Search();
				}
				else
				{
					document.location.assign(url);
				}
			}
		);
	}
};
//刷新窗口数据
function reloadDoc()
{
	if(top!=self)
	{
		Search();
	}
	else
	{
		document.location.assign(document.location.href);
	}
};
//get请求
function ajaxGet(url)
{
	url=url.addquerystring("t",now());
	$.ajax({
		   type: 'get',
		   async: false,
		   url: url,
		   dataType: "html",
		   success: function(data){
			}
	});
};
//post请求
function ajaxPost(url,obj)
{
	$.ajax({
		   type: 'post',	
		   async: false,
		   url: url,
		   data:obj,
		   dataType: "html",
		   success: function(data){
			}
	});
};
function TableSum(id,name)
{
	var table=$("#" + id);
	var tbody=table.find("tbody");	
	var trs=tbody.find("tr:visible");
	var result=0;
	trs.each(function(i,el){		
		var hj=getHTMLValue($(this).find("[postname='" + name + "']").val());//合计
		result+=hj;
	});
	return result;
};
//去掉多余HTML返回数值类型
function getHTMLValue(html)
{
	var value=0;
	html=html.replace(/ /g,"");
	html=html.replace(/&nbsp;/g,"");
	html=html.replace(/,/g,"");
	if(html.length==0){return value;}
	try 
	{		
		value = html.indexOf(".") > -1 ? parseFloat(html) : parseInt(html);
    }
	catch(e)
	{
        return 0;
    }
	return value;
};
//生成拼音
function MakePinyin(obj,objid)
{	
	var value = obj.value.length==0 ? "" : pinyinUtil.getFirstLetter(obj.value, true);
	$("#" + objid).val(value);
};
function IsMobile() 
{
    var userAgentInfo = navigator.userAgent.toLowerCase();
    var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone","iPad", "iPod", "Windows CE", "Windows Mobile", "UCWeb", "Midp"];
    var flag = false;
    for(var i = 0; i < Agents.length; i++) 
	{
        if (userAgentInfo.indexOf(Agents[i].toLowerCase()) > -1) 
		{
            flag = true;
            break;
        }
    }
    return flag;
};
function getReportHeight(obj)
{
	var rep=obj.parent();
	var height=rep.height();
	if(rep.find("h1").height()){height-=rep.find("h1").height()+14;}
	if(rep.find("p").height()){	height-=rep.find("p").height()+14;}
	return height;
};

function fileorpath_clear(obj)
{
	$("#" + obj).val('');
};
function fileLibrary_select(obj,path,basepath)
{
	var url = "../Plugins/FileSelect.aspx?obj=" + obj + (path.length > 0 ? "&path=" + path : "");
	if(basepath && basepath.length > 0){url+="&basepath=" + basepath;}
	url+= "&t=" + now();
    layer.open({
      type: 2,
      title: "选择文件",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	  area:IsMobile() ? ['95%','95%'] : ["60%" , "80%"],    
      //area : ["60%" , "80%"],	
	  // content: [url,'no'], 
	  content: url,
	  success: function(layero, index){arrLayerIndex.push(index);},
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){arrLayerIndex.pop();}
    });	
};
function path_select(obj,path)
{
	var url = "../Plugins/PathSelect.aspx?obj=" + obj + (path.length > 0 ? "&path=" + path : "");
	url+= "&t=" + now();
    layer.open({
      type: 2,
      title: "选择目录",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	  area:IsMobile() ? ['95%','95%'] : ["60%" , "40%"],    
	  btn: ['确定','取消'],
      //area : ["60%" , "80%"],	
	  // content: [url,'no'], 
	  content: url,
	  yes: function(index,layero)
	  {
		  var path=$(layero).find('iframe')[0].contentWindow.document.location.href.getquerystring("path");
		  $("#" + obj).val(path);
		  arrLayerIndex.pop();
		  layer.close(index);
	  },
	  success: function(layero, index){arrLayerIndex.push(index);},
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){arrLayerIndex.pop();}
    });	
};
//Excel导入
var uploadTempFile="";
function excel_import(area)
{
/*
layer.alert('欢迎访问 hangge.com', {
  resizing: function(layero){
    console.log(layero);
  }
});
*/
	var iframeWin;
	var url= "../Customs/base/ExcelImport.aspx?area=" + area;
	if(typeof(AppItem)=="string" && AppItem.length > 0){url+="&AppItem=" + AppItem;}
	if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
	url+= "&t=" + now();
	layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: "Excel导入",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
      area : ['95%' , '90%'],
      content: url,
	  success: function(layero, index){
		  arrLayerIndex.push(index);
		  
		  //var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		  //iframeWin = layero.find('iframe')[0].contentWindow;
		  // var path=$(layero).find('iframe')[0].contentWindow.document.location.href.getquerystring("path");
		  iframeWin = layero.find('iframe')[0];

		  
	  },
	  cancel: function(index, layero){
		  //arrLayerIndex.pop();

			   //alert( layero.find('iframe')[0].contentWindow.document.location);
	 },
	  end : function(index, layero, iframe){		  
		  //arrLayerIndex.pop();
		  //var _body = layer.getChildFrame('body', index);
    		//var win=$("#layui-layer-iframe" + index);			
		 	//alert(win.contentWindow);
			   //var res = window["layui-layer-iframe" + index].callbackdata(); 
			if(uploadTempFile.length>0)
			{
				removefile(uploadTempFile);
				uploadTempFile="";
			}
			 
		// alert( layero );
		  //var file=iframeWin.document.location.href.getquerystring("file");
		  //alert("end" + file);
		  document.location.assign(document.location.href);
	  }
    });
};
//自动回填
function autoFillN(obj,pid,objIds)
{
	var url=document.location.href;	
	url=url.removequerystring("debug");
	autoFill(obj,pid,objIds,url);
};
function autoFill(obj,pid,objIds,url)
{
	var objid=objIds.split(",");
	
	for(var t=0;t<objid.length;t++)
	{
		var file="";
		try
		{
			var arr=document.location.href.split("/");
			file=arr[arr.length-1].split(".")[0] + ".aspx";
		}
		catch(e)
		{
			file="Model.aspx";
		}
		var _pid=pid;
		if(obj.tagName=="SELECT")
		{
			
			if(obj.options[obj.selectedIndex].getAttribute("code"))
			{
				if(obj.options[obj.selectedIndex].getAttribute("code").length>0)
				{
					_pid=obj.options[obj.selectedIndex].getAttribute("code");
				}
			}
		}
		else
		{
			
			switch(obj.type)
			{
				case "radio":
					if(obj.getAttribute("code"))
					{
						if(obj.getAttribute("code").length>0)
						{
							_pid=obj.getAttribute("code");
						}
					}
					break;
				case "checkbox":
					if(obj.getAttribute("code"))
					{
						if(obj.getAttribute("code").length>0)
						{
							_pid=obj.getAttribute("code");
						}
					}
					break;
			}
		}

		var _url= file +  (!document.location.href.getquerystring("act") ? "?act=getdata" : "?act=edit");
		if(typeof(AppItem)=="string" && AppItem.length > 0){_url+="&AppItem=" + AppItem;}
		if(typeof(ModelID)=="string" && ModelID.length > 0){_url+="&ModelID=" + ModelID;}
		if(url){_url=url;}
		_url += "&Pid=" + _pid;
		_url += "&obj=" + objid[t];
		var query="";
		if(typeof(autoFill_before)=="function")
		{
			var _back = autoFill_before(objid[t]);
			if(typeof(_back)=="object")
			{
				query=_back.query.replace("?","");				
				if(query.length>0)
				{
					var arr=query.split("&");
					for(var x=0;x<arr.length;x++)
					{
						var arr2=arr[x].split("=");
						if(arr2.length==2)
						{
							_url=_url.addquerystring(arr2[0],arr2[1]);
						}
						//alert(arr[x] + "::" + arr2.length);
					}
					//alert(query + "::" + arr.length);
					//if(query.indexOf("&")!=0){query="&" + query;}	
					//alert(_url);
				}
			}
		}
		//if(query.length>0){_url+=query;}
		_url += "&t=" + now();
		//alert(_url);
		//return;
		$.ajax({
		type: "GET",
		async: false,
		url: _url,
		dataType: "json",
		success: function(data)
		{
			//alert(JSON.stringify(data));
			if(!data){return;}
			var box=$("#" + objid[t] + "_box");
			var controltype=box.attr("etype");
			var html='';
			//alert(controltype + "::" + JSON.stringify(data));
			switch(controltype)
			{
				case "autoselect":
					$("#" + objid[t]+"_1").get(0).length=1;
					for(var i=2;i<10;i++)
					{
						var tmp=getobj(objid[t] + "_" + i);
						if(!tmp){break;}
						tmp.parentNode.removeChild(tmp);
					}
					 $.each(data, function()
					 {
						$("#" + objid[t]+"_1").append('<option value="' + this["value"] + '">' + this["text"] + '</option>'); 
					 });
					break;
				case "select":
					 $("#" + objid[t]).get(0).length=1;
					 $.each(data, function()
					 {
						$("#" + objid[t]).append('<option value="' + this["value"] + '">' + this["text"] + '</option>'); 
					 });
					 if(typeof($("#" + objid[t]).get(0).onchange)=="function")
					 {
						$("#" + objid[t]).trigger("change");
					 }
					break;
				case "radio":
					$.each(data, function(i,v)
					 {
						html+='<input etype="checkbox" type="radio" name="' + objid[t] + '" id="' + objid[t] + '_' + (i+1) +  '" value="' + this["value"]+ '" fieldname="'+ (box.attr("fieldname") ? box.attr("fieldname") : "")  +'" notnull="'+ (box.attr("notnull") ? box.attr("notnull") : "")  +'" text="'+this["text"] +'" defaultvalue="">';
						html+='<label for="' + objid[t] + '_' + (i+1) +  '">' +  this["text"]  + '</label>';
					 });
					box.html(html);
					break;
				case "checkbox":
					$.each(data, function(i,v)
					 {
						html+='<input etype="checkbox" type="checkbox" name="' + objid[t] + '" id="' + objid[t] + '_' + (i+1) +  '" value="' + this["value"]+ '" fieldname="'+ (box.attr("fieldname") ? box.attr("fieldname") : "") +'" notnull="'+ (box.attr("notnull") ? box.attr("notnull") : "")  +'" text="'+this["text"] +'" defaultvalue="">';
						html+='<label for="' + objid[t] + '_' + (i+1) +  '">' +  this["text"]  + '</label>';
					 });
					box.html(html);
					break;
			}
			if(typeof(autoFill_finsh)=="function"){autoFill_finsh(pid,objid[t]);}
			if(typeof(autoFill_finish)=="function"){autoFill_finish(pid,objid[t]);}
			
			/*
			
			
			//$("#" + ObjID).empty();
			
			 */
		}
		});
	}
};
//Ajax提交表单
function ajaxSubmit(frm)
{
	//if(Attribute(frmaddoredit,"finsh")=="true"){return;}
	//alert($(frm).serialize());
	//return;
	var _back=eCheckform(frm);
	if(!_back){return;}	
	//alert( $(frm).serialize());
	//document.write($(frm).serialize());
	//return;
	$.ajax({
			type: 'post',
			async: false,
			url: $(frm).attr("action"),			
			data: "ajax=true&" + $(frm).serialize(),
			//data:{ajax:"true",value:"22"},
			dataType: "json",
			success: function(data)
			{
				//alert(data);
				//alert(JSON.stringify(data));
				if(parseBool(data.success))
				{
					$(frm).find("input,select,textarea").each(function(i,el)
					{
						var v=$(el).val();
						if(v.length>0)
						{
							//alert(v.decode());
							$(el).val(v.decode());
						}
					});
					if(frm["id"] && typeof(data.id) != "undefined")
					{
						frm["id"].value = data.id;						
					}
					if(typeof(data.message)==="undefined")
					{
						layer.msg("保存成功!");
					}
					else
					{
						layer.msg(data.message);
					}
					$(frm).find("input[type='password']").each(function(i,elem){
						var pwdMD5Twice = elem.value;	
						if(pwdMD5Twice.length>100) 
						{
							elem.value="******";
						}
					});
				}
				else
				{
					if(typeof(data.message)!=="undefined")
					{
						layer.msg(data.message);
					}
				}
			}
	});
};
//帮助中心窗口
function showHelp(ID)
{	
	var url="http://frame.eketeam.com/HelpContent.aspx?id=" + ID;
	url+= "&t=" + now();
	layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: "帮助中心",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
      area : ['1000px' , '65%'],
      content: url,
	  success: function(layero, index){arrLayerIndex.push(index);},
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){arrLayerIndex.pop();}
    });
};
//生成网址二维码
function getURLCode(title,_url)
{
	//var url= "UrlCode.aspx?url=" + encodeURIComponent(_url);
	var url= virtualPath + "Plugins/UrlCode.aspx?url=" + encodeURIComponent(_url);
	url+= "&t=" + now();
	var html='<div style="text-align:center;line-height:35px;margin:10px;">' + title + '</div>';
	html+='<div style="margin:10px;text-align:center;"><img src="' + url + '" width="185"></div>';
	layer.open({
  	type: 1
	,area:['400px','400px']
	//,shade: 0.2 //透明度
  	,title: "手机扫一扫-预览" //不显示标题
	,closeBtn: 1
	,scrollbar: false
	,shadeClose: true //开启遮罩关闭
	//,content:'<div style="padding:10px;"><img src="' + src + '" width="'+ w +'"></div'
  	,content:html
	,btn: ['关闭']
	,end: function(){}
	,success: function(layero, index){}
	
	});
};
//唯一性验证
function checkSingleN(obj,singleType,modelid)
{
	var url=document.location.href;	
	url=url.addquerystring("obj","checksingle");
	if(modelid){url+="&modelid=" + modelid;}
	var frm=$(obj).parents("form:first");
	if(frm)
	{
		var id=frm.find("#ID").val();
		if(id&&id.length>0)
		{
			url=url.addquerystring("id",id);
		}
	}
	url+="&t=" + now();
	checkSingle(obj,url,singleType);
}
function checkSingle(obj,url,singleType)
{
	//checkSingle:0,一起验证；1，逐个验证
	var inputs=$(document.body).find("[checkvalue]");
	/*
	if(inputs.length == 1 && Attribute(obj,"ovalue") == obj.value && obj.value.length > 0)//编辑
	{
		//obj.setAttribute("checkvalue","false");
		return;
	}
	*/
	//document.title=inputs.length;
	var _url=document.location.href;	
	//_url=_url.addquerystring("act","getdata");
	_url=_url.addquerystring("act","checksingle");	
	_url+="&t=" + now();
	if(url){_url=url;}
	//alert(_url);
	//return;
	var cancel_list=",";
	var hasnull=false;
	var haschange=false;
	inputs.each(function(i,el){
		if(cancel_list.indexOf("," + el.name.toLowerCase() + ",")>-1){return true;}	
		var type=Attribute(el,"type").toLowerCase();	
		var value="";
		var ovalue=$(el).attr("ovalue");
		if(ovalue.length==0){haschange=true;}
		switch(type)
		{
			case "checkbox":				
				$("input[name='" + el.name + "']:checked").each(function(i,sel){
					if(i>0){value+=",";}
					var _value=$(sel).val();
					if(ovalue.length>0 && _value!=ovalue ){haschange=true;}
					if(_value.toLowerCase()=="true"){_value="1";}
					if(_value.toLowerCase()=="false"){_value="0";}					
					value+=_value;
				}); 
				break;
			case "radio":
				value= $("input[name='" + el.name + "']:checked").val();
				if(ovalue.length>0 && value!=ovalue){haschange=true;}
				break;
			default:
				value=$(el).val();
				if(ovalue.length>0 && value!=ovalue){haschange=true;}
				break;
		}
		if(value.length==0){hasnull=true;return false;}	
		if(value.toLowerCase()=="true"){value="1";}
		if(value.toLowerCase()=="false"){value="0";}
		_url+= "&" + el.name + "=" + value;
		cancel_list+=el.name.toLowerCase() + ",";
	});

	if(hasnull || !haschange){return;}
	
	$.ajax({
			type: 'get',
			async: false,
			url: _url,
			dataType: "json",
			success: function(data)
			{
				if(parseBool(data.success))
				{					
					//obj.setAttribute("checkvalue",data.value);
					inputs.each(function(i,el){
						//el.setAttribute("checkvalue",data.value);
							$(el).prop("checkvalue",data.value);
							$(el).attr("checkvalue",data.value);
					});
					if(inputs.length==1 && data.value=="true")
					{
						//alert(Attribute(obj,"fieldname") + "已经存在!");

					}

					if(inputs.length==1 && data.value=="true" && typeof(layer)!="undefined")
					{
						layer.msg($(inputs[0]).attr("fieldname") + "已经存在!");
					}
					//alert(singleType + "::" + inputs.length);
				}
			}
		});
};
//颜色选择器
function showColor(id)
{	
	var url=virtualPath + "Plugins/eColor.html?id=" + id + "&t=" + now();
	layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: "颜色选择",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	  area:IsMobile() ? ['280px' , '246px'] : ['270px' , '236px'],   
      content: url,
	  
	  success: function(layero, index){arrLayerIndex.push(index);},
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){arrLayerIndex.pop();}
    });
};
//百度地图
function openbdMap(id)
{	
	var url=virtualPath + "Plugins/bdmap.html?id=" + id;
	url+= "&t=" + now();
	layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: "百度地图位置",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	  area:IsMobile() ? ['95%','65%'] : ['640px' , '580px'],   
      content: url,
	  success: function(layero, index){arrLayerIndex.push(index);},
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){arrLayerIndex.pop();}
	 
    });
};
//返回
function goBack()
{
	//if(top!=window)
	if(top!=self)//Frame打开
	{
		if(parent.arrLayerIndex.length>0)
		{
			parent.layer.close(parent.arrLayerIndex.pop());
		}
		else
		{
			history.back();
		}  
	}
	else
	{
		history.back();		
	}
};
function goAction(obj,text)
{
	var _back=confirm('确认要' + text + '吗？');
	if(!_back){return;}
	var url=obj.getAttribute("ehref");	
	$.ajax({
		   type: "get",
		   async: false,
		   url:url,
		   dataType: "html",
		   success: function(data)
		   {
			   layer.close(arrLayerIndex.pop());
			   var curtab = $(document).find(".eFrameTab dt a.cur");
			   var win= $(document).find(".eFrameTab dd iframe:eq(" + curtab.index() + ")").get(0).contentWindow;
			   var page=$(win.document).find("#page").val();
			   win.Search(page);
		   }
	});
};
function goLink(obj,width,height)
{
	if(!width) width="95%";
	if(!height) height="95%";
	var url=obj.getAttribute("ehref");	
	if(url.toLowerCase().indexOf("appitem=")==-1)
	{
		if(typeof(AppItem)=="string" && AppItem.length>0){url=url.addquerystring("AppItem",AppItem);}
	}
	if(obj.getAttribute("etext"))
	{
		
		var _text = obj.getAttribute("etext");
        parent.eFrameTab_add(url, _text);
		return;
	}
	if(url.toLowerCase().indexOf("=del")>-1)
	{
		var _back=confirm('确认要删除吗？');
		if(!_back){return;}		
	}
	//展示
	if(url.toLowerCase().indexOf("value=")==-1 &&  url.toLowerCase().indexOf("=del")==-1 &&  url.toLowerCase().indexOf("=cancel")==-1  && (1==1 || url.toLowerCase().indexOf("=add")>-1 || url.toLowerCase().indexOf("=edit")>-1 || url.toLowerCase().indexOf("=copy")>-1 || url.toLowerCase().indexOf("=view")>-1 || url.toLowerCase().indexOf("=print")>-1 ))
		{
			//alert(1 + ":" + url);
			//if(url.indexOf(".aspx")== -1){url="ModelInfo.aspx" + url;}
			//else{url=url.replace("Model.aspx","ModelInfo.aspx");}
		 	//if(typeof(AppItem)=="string" && AppItem == url.getquerystring("appitem") )		
			
			if(url.toLowerCase().indexOf("act=")>-1 ){url=url.addquerystring("ajax","true");}
			//alert(url + "::" + url.toLowerCase().indexOf("=print"));

			var title=obj.innerText;
			if(title.indexOf("添加")>-1) {title="添加";}
			if(obj.getAttribute("etext")){title=obj.getAttribute("etext");}

			//var table=getobj("eDataTable");			
			//var rect = table.getBoundingClientRect();
			//var rc = document.body.getBoundingClientRect();
			
			//parent.layer.open({
			layer.open({
			  type: 2
			  ,title: title	
			  ,shadeClose: true //点击遮罩关闭层
			  //,area: [(rect.right-rect.left) + "px",(rc.bottom-rc.top-rect.top-10) + "px"]
			  //,offset: [rect.top + "px", rect.left + "px"]
			  //,area: ["95%","95%"]
			  ,area: [width,height]
			  ,content: url			  
			  ,success: function(layero, index)
			  {
				  arrLayerIndex.push(index);
			  }
			  ,cancel: function(index, layero)
			  {
				  arrLayerIndex.pop();
			  }
			  ,end : function(index)
			  {
				  arrLayerIndex.pop();
			  }
			});		

			/*
			var index = layer.open({
			  type: 2
			  ,title: title			
			  ,content: url
				
			});
			//layer.full(index);
			*/
			
			
			//document.location.assign(url);
			
			return;
		}

	$.ajax({
			   type: "get",
			   async: false,
			   url:url,
			   dataType: "html",
			   success: function(data)
			   {
				   //var page=$("#page").val();
				   //Search(page);
				   var curtab = $(document).find(".eFrameTab dt a.cur");
				   var win= $(document).find(".eFrameTab dd iframe:eq(" + curtab.index() + ")").get(0).contentWindow;
				   var page=$(win.document).find("#page").val();
				   win.Search(page);
			   }
			});
	
	
};
//首页
function page_First()
{
	var table=getobj("eDataTable");
	var page=getobj("page");
	if(!table || !page){return;}	
	var ajax = parseBool(table.getAttribute("ajax"));
	
	var num=parseInt(page.value);
	if(num<=1){return;}

	if(ajax)
	{
		Search(1);
	}
	else
	{
		var url=getPageUrl();

		if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}

		url=url.addquerystring("page","1");
		url=url.addquerystring("t",now());
		document.location.assign(url);
	}
};
//上一页
function page_Previous()
{	
	var table=getobj("eDataTable");
	var page=getobj("page");
	if(!table || !page){return;}	
	var ajax = parseBool(table.getAttribute("ajax"));
	var num =parseInt(page.value);
	var maxnum = parseInt(page.getAttribute("maxvalue"));
	if(num<=1) {return;}
	num-=1;
	if(ajax)
	{
		Search(num);
	}
	else
	{
		var url=getPageUrl();
		if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}
		url=url.addquerystring("page",num);
		url=url.addquerystring("t",now());
		document.location.assign(url);
	}
};
//下一页
function page_Next()
{	
	var table=getobj("eDataTable");
	var page=getobj("page");
	if(!table || !page){return;}	
	var ajax = parseBool(table.getAttribute("ajax"));
	
	var num =parseInt(page.value);
	var maxnum = parseInt(page.getAttribute("maxvalue"));
	if(num>=maxnum) {return;}
	num+=1;
	if(ajax)
	{
		Search(num);
	}
	else
	{
		var url=getPageUrl();
		if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}
		url=url.addquerystring("page",num);
		url=url.addquerystring("t",now());
		document.location.assign(url);
	}
};
//尾页
function page_Last()
{
	var table=getobj("eDataTable");
	var page=getobj("page");
	if(!table || !page){return;}	
	var ajax = parseBool(table.getAttribute("ajax"));
	
	var num =parseInt(page.value);
	var maxnum = parseInt(page.getAttribute("maxvalue"));
	if(num>=maxnum) {return;}
	

	if(ajax)
	{
		Search(maxnum);
	}
	else
	{
		var url=getPageUrl();
		if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}
		url=url.addquerystring("page",maxnum);
		url=url.addquerystring("t",now());
		document.location.assign(url);
	}
};
//获取页面URL
function getPageUrl()
{
	var url=$("#frmsearch").attr("action") || document.location.href;	
	if(document.forms["frmsearch"])
	{
		var info=getSearchInfo(frmsearch);		
		var hash=info.hash;
		var keys = hash.keys();
		//for(var entry in keys)
		for(var i=0;i<keys.length;i++)
		{
			//var key=keys[entry];
			var key=keys[i];
			var value=hash.get(key);
			url=url.addquerystring(key,value);		
			//alert(key + "=" + value);
		}
	}
	if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}
	return url;
};
//ajax搜索、跳转分页
function Search(page)
{
	page = page || $("#page").val() || 1;	
	var url=$("#frmsearch").attr("action") || document.location.href;	
	url=url.addquerystring("page",page);
	url=url.addquerystring("ajax","true");	
	if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}
	
	var  btn=$("#btn_Export");
	var exportbtn=btn.length==0?null:btn;	
	var replaceexp=false;
	var _exurl="";
	if(exportbtn)
	{
		_exurl=exportbtn.attr("basehref");	
		if(_exurl){replaceexp=true;}
	}	
	if(document.forms["frmsearch"])
	{
		var info=getSearchInfo(frmsearch);		
		var hash=info.hash;
		var keys = hash.keys();
		//for(var entry in keys)
		for(var i=0;i<keys.length;i++)
		{
			//var key=keys[entry];
			var key=keys[i];
			var value=hash.get(key);
			url=url.addquerystring(key,value);		
			
			//alert(key + "=" + value);
			if(replaceexp){_exurl=_exurl.addquerystring(key,value);}
		}
		if(replaceexp)
		{
			exportbtn.attr("href",_exurl);
		}
	}
	url=url.removequerystring("debug");
	url=url.addquerystring("t",now());
	
	
	
	var table=getobj("eDataTable");//无数据时没有
	
	if(table)
	{
		var orderby=table.getAttribute("orderby");
		url=url.removequerystring("orderby");	
		if(orderby.length>0)
		{
			url=url.addquerystring("orderby",orderby);
		}
	}


	var Loading = getobj("DivLoading");
	if(!Loading)
	{	
		
		//var rect = table.getBoundingClientRect();
		var rect = document.body.getBoundingClientRect();
	
		Loading = document.createElement("div");
		Loading.id="DivLoading";
		Loading.className="eDataTable_Loading";
		Loading.style.zIndex="200";	
		Loading.style.width = (rect.right -  rect.left) + "px";
		Loading.style.height = (rect.bottom -  rect.top) + "px";	
		//Loading.style.top = rect.top + "px";
		//Loading.style.left = rect.left + "px";
		Loading.style.top =  "0px";
		Loading.style.left =  "0px";
		document.body.appendChild(Loading);
	}
	

	//alert(url);
	//return;

	//$(".page").val(page);
	
	$.ajax({
		   type: "get",
		   async: false,
		   url:url,
		   dataType: "json",
		   success: function(data)
		   {

			   var dt=getobj("divlist");
			   if(dt)
			   {
			   		$("#divlist").html(data.table.decode());
			   }
			   else
			   {
				   
				   $("#eDataTable").prop("outerHTML", data.table.decode());
			   }

			   
			   //$("#eDataTable tbody").html(data.tbody.decode());
			   //$("#epage").html(data.epage.decode());
			   var pg=getobj("epage");
			   if(pg)
			   {
			   		pg.innerHTML=data.epage.decode();
			   }
			   else
			   {
				   $(".epager").prop("outerHTML", data.epage.decode());
			   }
			   deleteObject(Loading);
			   etable_init();
			    $("span.more").each(function(index, val) {
						var ele = $(this);		
						ele.on("click", function() {
							showOptionMenu(this);			
						});	
					
					});
			   
			   var table=document.getElementById("eDataTable");
			   if(table)
			   {
				   /*
				   if(table.parent)
				   {
				   		Table_Init_Tbody(table.parent);
				   }
				   */
				  
			   }
			   
		   }
	});
	

	
};
//提交搜索
function goSearch(frm)
{
	var info=getSearchInfo(frm);
	document.location=info.url;
	return false;
};
function getEasyUISearch(frm)
{
	var obj=new Object();
	var info=getSearchInfo(frm);
	var hash=info.hash;
	var keys = hash.keys();
	//for(var entry in keys)
	for(var i=0;i<keys.length;i++)
	{
		//var key=keys[entry];
		var key=keys[i];
		var value=hash.get(key);
		obj[key] = value;
	}	
	return obj;
};
function showPower(obj)
{
	var div=obj.parentNode;
	div=div.nextSibling;
	while(div.tagName!="DIV")
	{
		div=div.nextSibling;
	}
	//if(div.nodeType==3){div=div.nextSibling;}
	if(obj.className=="close")
	{
		obj.className="open";
		div.style.display="";
	}
	else
	{
		obj.className="close";
		div.style.display="none";
	}
};
//角色选择、取消选择
function selectRoles(obj)
{
	//var url="?act=getrole&roleid=" + obj.value + "&t=" + now();

	$(".powerContent input[type='checkbox']").attr("checked",false);
	var div=$(obj).parent().parent();
	var inputs=div.find("input:checked");
	//if(inputs.length==0){return;} //还有用户权限，
	var values="";
	inputs.each(function(i,elem){
		if(i>0){values+=",";}			 
		values+=elem.value;
    });

	var url=document.location.href;	
	if(typeof(AppItem)=="string" && AppItem.length > 0){url=url.addquerystring("AppItem",AppItem);}
	url=url.addquerystring("act","getrole");
	//url=url.addquerystring("roleid",obj.value);
	url=url.addquerystring("roleid",values);	
	url=url.addquerystring("t", now());
	
	//alert(url);
	//return;
	//if(obj.type=="radio"){$(".powerContent input[type='checkbox']").prop("checked",false);}

	$.ajax({
		   type: "get",
		   async: false,
		   url:url,
		   dataType: "json",
		   success: function(data)
		   {
			   //var json=new eJson(data);
			   //alert(json.toJson());
			   //$("#json").val( now() + "\n" +  json.toJson());
			   if(!data){return;}
			  // alert(JSON.stringify(data));
			   for(var i=0;i<data.length;i++)
			   {
				   for(p in data[i])
				   {
					   
					   if(p.toLowerCase()=="convert"){continue;}
					   if(typeof(data[i][p])=="function"){continue;}
					   if(p.toLowerCase() == "modelid" || p.toLowerCase() == "applicationitemid" || p.toLowerCase() == "applicationid"){continue;}
						//if(inputs.length==1) alert(p + "::" + data[i][p]);
						if(data[i][p].toLowerCase() == "true")
						{
							var sel=(data[i]["ApplicationItemID"] ?  getobj("model_" + p.toLowerCase() + "_" + data[i]["ApplicationItemID"].replace(/-/g,"") + "_" + data[i]["ModelID"].replace(/-/g,"")) : getobj("model_" + p.toLowerCase() + "_" +  data[i]["ModelID"].replace(/-/g,"")) );
							if(sel)
							{
								sel.checked=true;//obj.checked;
							}
							if(p.toLowerCase()=="list")
							{
								sel=(data[i]["ApplicationItemID"] ? getobj("model_" + data[i]["ApplicationItemID"].replace(/-/g,"") + "_" + data[i]["ModelID"].replace(/-/g,"")) : getobj("model_" + data[i]["ModelID"].replace(/-/g,"")));

								if(sel)
								{
									sel.checked=true;//obj.checked;
								}
								
							}
						}
				   }
			   }
		   }
	});
	//alert(url + "::" + obj.checked);	
};
//全选模块权限
function SelectAllItem(obj,type)
{
	$("input[name*='" + type + "']").each(function(i,el){
		//$(this).trigger("click");
		$(this).prop("checked",obj.checked);
		if(type=="model_list_")
		{
			userCanelAll(el);
			if(!obj.checked)
			{
				$("#allmodelbody input").prop("checked",obj.checked);
			}
		}
	});
};
function SelectAllModel(obj)
{
	$(".modelname").each(function(i,el){
		$(this).find("input:eq(0)").prop("checked",obj.checked);
		userSelectAll($(this).find("input:eq(0)").get(0));
		$("#allmodelbody input").prop("checked",obj.checked);
	});
};
//用户权限-全选
function userSelectAll(obj)
{
	var div=obj.parentNode.parentNode;	
	var inputs=div.getElementsByTagName("input");
	for(i=0;i < inputs.length;i++)
	{
		if(inputs[i]==obj || inputs[i].type.toLowerCase()!="checkbox"){continue;}
		inputs[i].checked=obj.checked;
	}
};
//用户权限-列表权限
function userCanelAll(obj)
{
	var div=obj.parentNode.parentNode;	
	var inputs=div.getElementsByTagName("input");
	if(obj.checked)
	{
		inputs[0].checked=true;
		return;
	}
	for(i=0;i < inputs.length;i++)
	{
		if(inputs[i]==obj || inputs[i].type.toLowerCase()!="checkbox"){continue;}
		inputs[i].checked=false;
	}
};

//$(function (){ });
//$(function (){
	//$(document).keydown(function(e){
//document.title=e.keyCode;
//});
//});

function selectselItems(obj)
{
	//$("input[name='fillselitem']").prop("checked",obj.checked);
	//$("input[name='fillselitem']:not(:checked)").each(function(i,el){
	$("input[name='fillselitem']").each(function(i,el){
		 $(this).get(0).click();
	});
};
function excel_add(obj,ModelID)
{
	var table=$(obj).parents("table:first");
	var tfoot=table.find("tfoot");
	var tr=tfoot.find("tr")[0].cloneNode(true);	
	var tbody=table.find("tbody");
	var _max=tbody.children().length + 1;
	$(tr).find("input[type='radio']").each(function(i,el){
		$(this).attr("name","row_" + _max + "_" + $(this).attr("name"));	 
	});	
	tbody[0].appendChild(tr);
	tbody.find("tr:visible").each(function(i,el){
		$(this).find("td:eq(1)").html(i+1);
	});
	//$("#count_" + ModelID).val(tbody.find("tr:visible").length);	
	var count;
	if(form_area)
	{
		count=form_area.find("#count_" + ModelID);
		count=count.length>0 ? count[0] : count=getobj("count_" + ModelID);
	}
	else
	{
		count=getobj("count_" + ModelID);
	}
	if(count)
	{
		count.value=tbody.find("tr:visible").length;
	}
	
	excel_pack(ModelID);
	//alert(table.tagName);
	//var tr=tfoot.getElementsByTagName("tr")[0].cloneNode(true);
	if(typeof(submodel_onChange)=="function")
	{
		var list_trs=tbody.find("tr:visible");
		submodel_onChange(ModelID,list_trs,tbody);//数据为空
	}
	//alert("add line or select more lines!");
	
};
function excel_delete(obj,ModelID,cancelconfirm)
{
	if(!cancelconfirm)
	{
		if(!confirm("确认要删除吗？")){return;}
	}
	var table=$(obj).parents("table:first");
	form_area=table.parent();
	
	var tbody=table.find("tbody");
	var tr=$(obj).parents("tr:first");
	var index=tr.index();
	//var input=getobj("eformdata_" + ModelID);	
	var input;
	if(form_area)
	{
		input=form_area.find("#eformdata_" + ModelID);		
		input=input.length>0 ? input[0] : getobj("eformdata_" + ModelID);
	}
	else
	{
		input=getobj("eformdata_" + ModelID);
	}

	
	
	
	var model=input.value.toJson();
	//model.Convert=true;	
	//alert(index + "::" + model.toJson());
	//return;
	var _model=model.get("eformdata_" + ModelID);
	_model=_model[index];
	
	
	tr.find("input[name='Delete']").val("true");
	
	if(_model["ID"].length==0)
	{
		_model=model.get("eformdata_" + ModelID)
		_model.remove(index);
		tr.remove();
	}
	else
	{
		_model["Delete"]="true";
		tr.hide();
	}
	input.value=model.toJson();	
	//excel_pack(ModelID);
	tbody.find("tr:visible").each(function(i,el){
		$(this).find("td:eq(1)").html(i+1);
	});
	//$("#count_" + ModelID).val(tbody.find("tr:visible").length);
	var count;
	if(form_area)
	{
		count=form_area.find("#count_" + ModelID);
		count=count.length>0 ? count[0] : count=getobj("count_" + ModelID);
	}
	else
	{
		count=getobj("count_" + ModelID);
	}
	if(count)
	{
		count.value=tbody.find("tr:visible").length;
	}
	
	
	
	if(typeof(submodel_onChange)=="function")
	{
		var list_trs=tbody.find("tr:visible");
		submodel_onChange(ModelID,list_trs,tbody[0]);
	}
};
function excel_pack(ModelID)
{
	//var table=$("#eformlist_" + ModelID);
	var table;
	if(form_area)
	{
		table=form_area.find("#eformlist_" + ModelID);
		if(table.length==0)
		{
			table=$("#eformlist_" + ModelID);
		}
	}
	else
	{
		table=$("#eformlist_" + ModelID);
	}

	//clearPack($(table));
	
	var tbody=table.find("tbody");
	var tfoot=table.find("tfoot");
	if(tfoot.length>0){addPack(tfoot);}
	//var input=getobj("eformdata_" + ModelID);
	var input;
	if(form_area)
	{
		input=form_area.find("#eformdata_" + ModelID);		
		input=input.length>0 ? input[0] : getobj("eformdata_" + ModelID);
	}
	else
	{
		input=getobj("eformdata_" + ModelID);
	}

	
	
	var model=input.value.toJson();	
	//model.Convert=true;
	//alert(JSON.stringify(model));
	var data="[]".toJson();	
	//data.Convert=true;	
	tbody.find("tr").each(function(i,el){
		var obj=nodeToJson(el);
		data.append(obj);
	});
	model["eformdata_" + ModelID]=data;	
	input.value=model.toJson();
	
	
	//addPack($(table));
};
//兼容自动上传文件
function autoupload_check(obj)
{
	var allowexts=obj.getAttribute("allowexts") || "";
	var preventexts=obj.getAttribute("preventexts") || "";
	if(allowexts.length>0){allowexts+=".";}
	if(preventexts.length>0){preventexts+=".";}
	if (obj.files)
	{		
		for(var i=0;i<obj.files.length;i++)
        {
			var ext=obj.files[i].name.fileExtension();
			if(ext.length==0||ext.indexOf(".")!=0)
			{
				 obj.value = "";
                 top.layer.msg("文件类型错误!");
				 return false;
			}
			if(allowexts.length>0)
			{
				if(allowexts.toLowerCase().indexOf(ext + ".") == -1)
                {
					obj.value = "";
                 	//layer.msg("文件类型" +  ext + "被禁止上传!");
					top.layer.msg("只允许上传" + allowexts.substring(0,allowexts.length-1) + "类型的文件!");
				 	return false;
				}
			}
			else
			{
				if(preventexts.toLowerCase().indexOf(ext + ".") > -1)
                {
					obj.value = "";
                 	top.layer.msg("文件类型" +  ext + "被禁止上传!");
				 	return false;
				}
			}
		}
	}
	else
	{
		var ext=obj.value.fileExtension();
		if(ext.length==0||ext.indexOf(".")!=0)
		{
			obj.value = "";
            top.layer.msg("文件类型错误!");
			return false;
		}
		if(allowexts.length>0)
		{
			if(allowexts.toLowerCase().indexOf(ext + ".") == -1)
            {
				obj.value = "";
                //layer.msg("文件类型" +  ext + "被禁止上传!");
				top.layer.msg("只允许上传" + allowexts.substring(0,allowexts.length-1) + "类型的文件!");
				return false;
			}
		}
		else
		{
			if(preventexts.toLowerCase().indexOf(ext + ".") > -1)
            {
				obj.value = "";
                top.layer.msg("文件类型" +  ext + "被禁止上传!");
				return false;
			}
		}
    }
	return true;	
};
function autoupload_change(obj)
{
	var attach=obj.value;
	if(attach == undefined || attach == "")
	{
		//alert("请选择文件");
        return;
    }
	var result=autoupload_check(obj);
	if(!result){return;}
	
	var posturl=obj.getAttribute("posturl");
	var url = posturl == null ? virtualPath + "Plugins/ProUpload.aspx?type=file" : posturl;
	if(url=="auto")
	{
		url=document.location.href.addquerystring("act","upload");
		url=url.addquerystring("ajax","true");
	}
	if (obj.files)
	{
		autopostfile(obj,url);
    }
	else
	{
	   	autopostfile_ie(obj,url);
    }
};
function autopostfile(obj,url)
{
	var formData = new FormData();
	for(var i=0;i<obj.files.length;i++)
	{
		formData.append('files', obj.files[i], obj.files[i].name);
	}
	$.ajax({
		type: "post", 
		async: false,
		data:formData,
        url:url,
        dataType: "json",
		contentType: false,
		cache: false,//上传文件无需缓存
        processData: false,//用于对data参数进行序列化处理 这里必须false
        success: function (data)
		{
			layer.msg(data.message);
			obj.value="";
			var callback=$(obj).attr("callback");
			if(callback)
			{
				//eval("if(typeof(" + callback + ")=='function'){" + callback + "(" + data.files +  ");}");
				if(data.files)
				{
					eval(callback + "(data.files);");
				}
				else
				{
					eval(callback + "(data);");
				}
			}			
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {}
    });
};

function autopostfile_ie(obj,url)
{
	$.ajaxFileUpload ({
		type: "post",
		async: false,
		url: url, //用于文件上传的服务器端请求地址 
		secureuri: false, //一般设置为false 
		fileElementId: $(obj).attr("id"), //文件上传空间的id属性  <input type="file" id="file" name="file" /> 
		dataType: "json", //返回值类型 一般设置为json 
		success: function (data, status)  //服务器成功响应处理函数
        {
			layer.msg(data.message);
			obj.value="";
			var callback=$(obj).attr("callback");
			if(callback)
			{
				//eval("if(typeof(" + callback + ")=='function'){" + callback + "(" + data.files +  ");}");
				if(data.files)
				{
					eval(callback + "(data.files);");
				}
				else
				{
					eval(callback + "(data);");
				}
			}
		}, 
		error: function (data, status, e)//服务器响应失败处理函数
        {
			//alert("error");
			//alert(e); 
		} 
	});	
	//alert(2);
};
//删除临时文件
function removefile(file)
{
	if(file.toLowerCase().indexOf("upload/")>0){file=file.substring(file.toLowerCase().indexOf("upload/"));}
	var url=virtualPath + "Plugins/ProUpload.aspx?act=del&file=" + file;
	$.get({url:url,async:false});
};
//读取excel文件返回json
function exceltojson(file)
{
	if(file.toLowerCase().indexOf("upload/")>0){file=file.substring(file.toLowerCase().indexOf("upload/"));}
	var url= virtualPath + "Plugins/ExcelToJson.aspx?path=" + file;
	var obj=[];
	$.ajax({
			type: "get",
			async: false,
			url: url,
			dataType: "json",
			success: function(result)
			{
				obj=result.data;
			}
	});
	return obj;
};
function addrow(obj,modelid)
{
	var table=$("#eformlist_" + modelid);
	if(!table){return null;}
	var tbody=table.find("tbody");
	var tfoot=table.find("tfoot");
	if(tfoot.length>0)
	{
		var tr=tfoot[0].getElementsByTagName("tr")[0].cloneNode(true);
		var _max=tbody.children().length + 1;
		$(tr).find("input[type='radio']").each(function(i,el){
			$(this).attr("name","row_" + _max + "_" + $(this).attr("name"));	 
		});	
		tbody[0].appendChild(tr);
		tbody.find("tr:visible").each(function(i,el){
			$(this).find("td:eq(1)").html(i+1);
		});
		var count=getobj("count_" + modelid);
		if(count)
		{
			count.value=tbody.find("tr:visible").length;
		}
		return tr;
	}
	return null;
};
function excel_SelectDataN(ModelID,singleFields)
{
	var fieldstr= singleFields || "";
	var fieldarr= [];
	if(fieldstr.length>0){fieldarr=fieldstr.split(",");}
	
	
	var src=getEventObject();
	//alert(src.tagName);
	if(src.tagName!="INPUT" && src.tagName!="TD" && src.tagName!="DIV" && src.tagName!="P"){return;}
	if(src.tagName=="INPUT" && src.name.toLowerCase()!="fillselitem"){return;}
	
	//return;
	
	
	//var tb=$("#eformlist_" + ModelID,parent.document);
	var tb;
	if (parent.form_area)
    {
		tb=$("#eformlist_" + ModelID,parent.form_area);
	}
	else
	{
		tb=$("#eformlist_" + ModelID,parent.document);
	}
	
	var chk=null;
	if(src.tagName=="INPUT")
	{
		chk=src;
	}
	else
	{		
		chk=$(src).parents("tr:first").find("input[name='fillselitem']")[0];
		chk.checked=!chk.checked;
	}	
	
	var _tr=$(chk).parents("tr:first")[0];
	var values = $(_tr).attr("jsondata");
	var json=decode64(values);
	var data=JSON.parse(json);
	//alert(json);
	if(chk.checked) //add
	{
		//批量添加和单个添加混乱		
		//alert(parent.fillparent);
		var obj=tb.find("thead td a:eq(0)");
		parent.excel_add(obj,ModelID);
		var tr=tb.find("tbody tr:last");
		parent.fillparent=tr[0];
		FillData2(values,true);
		parent.excel_pack(ModelID);
		//回调函数-删除
		if(typeof(parent.submodel_onChange)=="function")
		{
			var table=obj.parents("table:first");
			var tbody=table.find("tbody");
			var list_trs=tbody.find("tr:visible");
			parent.submodel_onChange(ModelID,list_trs,tbody);
		}
	}
	else
	{
		//alert(JSON.stringify(data));
		var trs = $(parent.document).find(".excelTable tbody tr:visible");
		for(var x = 0; x < trs.length; x++)
		{
			var tr = trs[x];
			var has = true;
			$.each(data, function(idx, item)
			{
				var name = item["id"];
				if(fieldarr.length > 0 && fieldarr.indexOf(name)==-1){return true;}
				var value = item["value"];
				value = value.replace(/'/gi, "\\'");				
				if($(tr).find("[postname='" + name + "'][value='" + value + "']").length == 0)
				{
					has = false;
				}						
			});
			if(has)
			{
				var obj= $(tr).find(".btndel")[0];
				parent.excel_delete(obj,ModelID,true);
				break;
			}	
		}	
	}
};
function excel_SelectData(ModelID,values)
{
	var src=getEventObject();
	if(src.tagName!="INPUT" && src.tagName!="TD"){return;}
	if(src.tagName=="INPUT" && src.name.toLowerCase()!="fillselitem"){return;}
	//var chk=src.tagName=="INPUT" ? src : $(src).parents("tr:first").find("input[name='fillselitem']")[0];
	var tb=$("#eformlist_" + ModelID,parent.document);
	var chk=null;
	if(src.tagName=="INPUT")
	{
		chk=src;
	}
	else
	{
		chk=$(src).parents("tr:first").find("input[name='fillselitem']")[0];
		chk.checked=!chk.checked;
	}
	if(chk.checked) //add
	{
		//批量添加和单个添加混乱		
		//alert(parent.fillparent);
		var obj=tb.find("thead td a:eq(0)");
		parent.excel_add(obj,ModelID);
		var tr=tb.find("tbody tr:last");
		parent.fillparent=tr[0];
		
		//parent.FillData(values,true);
		FillData(values,true);
		parent.excel_pack(ModelID);
		
	}
	else
	{
		var _tr=$(chk).parents("tr:first")[0];
		var values = $(_tr).attr("fieldarrs");
		var arrs = values.split("~");		
		var trs = $(parent.document).find(".excelTable tbody tr:visible");
		var index=-1;
		for(var x = 0; x < trs.length; x++)
		{
			//alert(x);
            var tr = trs[x];
			var has = true;
			for(var i = 0; i < arrs.length; i++)
			{
				var arr = arrs[i].split("=");
                if (arr.length < 2) { continue; }
                var name = arr[0];
				var value = arr[1].decode().replace(/%u003d/gi, "=");
				value = value.replace(/'/gi, "\\'");
				if($(tr).find("[postname='" + name + "'][value='" + value + "']").length == 0)
				{
					has = false;
				}
			}			
			if(has)
			{
				//index=$(tr).index();
				var obj= $(tr).find(".btndel")[0];
				parent.excel_delete(obj,ModelID,true);
				break;
			}			
		}
		//alert("index=" + index);
		if(index>-1)
		{
			//var obj= $(parent.document).find(".excelTable tbody tr:eq(" + index + ") .btndel")[0];
			//parent.excel_delete(obj,ModelID,true);
		}
	}
	//parent.document.title=src.tagName + "::" + ModelID;	
};
//回填到表单
var fillparent=null;
function FillData2(values,cancelclose)//values=json+base
{
	var json=decode64(values);
	//alert(json);
	var data=JSON.parse(json);
	$.each(data, function(idx, item)
	{
		//alert(parent.fillparent.tagName);
		var objs= parent.fillparent.tagName == "TR" ||  parent.fillparent.tagName == "DD" ? $(parent.fillparent).find("[postname='" + this["id"] + "']") : $(parent.fillparent).find("[name='" + item["id"] + "']");
		//alert(objs + "::" + item["value"]);
		if(objs)
		{
			//alert(item["id"] + "::" + objs.length);
			if(objs.length==1)
			{
				objs[0].value=item["value"];
				objs.prop("value",item["value"]);
				objs.attr("value",item["value"]);
				//回填后异步加载
				if(typeof(objs[0].onchange)=="function")
				{
					objs.trigger("change");
				}
				var etype=objs[0].getAttribute("etype");
				//alert(etype);
				switch(etype)
				{
					case "date":
						objs[0].value=item["text"];
						break;
					case "departmentselect":
						var box=$(parent.fillparent).find("#" + item["id"] + "_box");
						$(parent.fillparent).find("[postname='" + item["id"] + "']").val(item["value"]);
						$(parent.fillparent).find("[postname='" + item["id"] + "_text']").val(item["text"]);						
						if(box.find(".useritem").length==1)
						{
							box.find(".useritem p").html(item["text"]);
						}
						else
						{
							var html='<a class="useritem" href="javascript:;">';
							//html += '<p>' + item["text"] + '</p><img src="../images/none.gif" onclick="multipleuser_delete(this);"></a>';//回填不给删除
							html += '<p>' + item["text"] + '</p></a>';
							if(box.find(".useritem_open").length>0)
							{
								box.find(".useritem_open").before(html);
							}
							else
							{
								box.append(html);
							}
						}
						break;
					case "singleuser":
						//alert("2" + etype);
						var box=$(parent.fillparent).find("#" + item["id"] + "_box");
						$(parent.fillparent).find("[postname='" + item["id"] + "']").val(item["value"]);
						$(parent.fillparent).find("[postname='" + item["id"] + "_text']").val(item["text"]);						
						if(box.find(".useritem").length==1)
						{
							box.find(".useritem p").html(item["text"]);
						}
						else
						{
							var html='<a class="useritem" href="javascript:;">';
							//html += '<p>' + item["text"] + '</p><img src="../images/none.gif" onclick="multipleuser_delete(this);"></a>';//回填不给删除
							html += '<p>' + item["text"] + '</p></a>';
							if(box.find(".useritem_open").length>0)
							{
								box.find(".useritem_open").before(html);
							}
							else
							{
								box.append(html);
							}
						}
						//alert(item["id"] + "::" + item["text"] + "::" + item["value"]);
						break;
					case "label":
						$(parent.fillparent).find("#" + item["id"] + "_box span:eq(0)").text(item["text"]);
						break;
					case "html":
						try{parent.KE.html(item["id"],objs[0].value);}catch(e){}
						try{parent.KE.setFullHtml(item["id"],objs[0].value);}catch(e){}
						break;
				}
				/*
				if(etype=="label")
				{	
					$(parent.fillparent).find("#" + item["id"] + "_box span:eq(0)").text(item["text"]);
				}
				if(etype == "html")
				{
					try{parent.KE.html(item["id"],objs[0].value);}catch(e){}
					try{parent.KE.setFullHtml(item["id"],objs[0].value);}catch(e){}
				}
				*/
			}
			else
			{
				var _vs="," + item["value"] + ",";
				for(var j=0;j < objs.length;j++)
				{
					if(_vs.indexOf("," + objs[j].value + ",")>-1)
					{
						objs[j].checked=true;
					}
					else
					{
						objs[j].checked=false;
					}
				}
			}
		}
	});
	if(typeof(parent.FillData_finish)=="function"){parent.FillData_finish();}
	if(!cancelclose && parent.arrLayerIndex.length>0)
	{
		parent.layer.close(parent.arrLayerIndex.pop());
	}				 
};
function FillData(values,cancelclose)
{
	//.replace("m&#179;","m³")
	//alert(parent.arrLayerIndex.length + "::" + str);
	//alert(window.opener);
	var arr=values.split("~");
	//alert(parent.fillparent.tagName + "::" + arr.length);
	//alert($(parent.fillparent).find("[name='Me2_F16']"));
	//alert(parent.fillparent.getElementsByName);		
	//alert($("[name='Me2_F16']",parent.fillparent).val());	
	//return;
	//alert(parent.fillparent.tagName);
	for(var i=0;i<arr.length;i++)
	{

		var objvalue=arr[i].split("=");
		if(objvalue.length<2){continue;}
		//if(objvalue[1].length==0){continue;}
		//var objs=parent.document.getElementsByName(objvalue[0]);
		//alert(objvalue[0]);
		var objs= parent.fillparent.tagName == "TR" ? $(parent.fillparent).find("[postname='" + objvalue[0] + "']") : $(parent.fillparent).find("[name='" + objvalue[0] + "']");
		//return;
		//alert(objs);
		if(objs)
		{
			//document.title+=":" + objvalue[1].decode();
			 //alert(objvalue[1].decode() + "::" + objs.length);
			if(objs.length==1)
			{
				var tmp=objvalue[1].decode().replace(/%u003d/gi,"=");
				
				objs[0].value=tmp;
				objs.prop("value",tmp);
				objs.attr("value",tmp);
				//回填后异步加载
				if(typeof(objs[0].onchange)=="function")
				{
					objs.trigger("change");
				}
				var etype=objs[0].getAttribute("etype");
				if(etype == "html")
				{
					try{parent.KE.html(objvalue[0],objs[0].value);}catch(e){}
					try{parent.KE.setFullHtml(objvalue[0],objs[0].value);}catch(e){}
				}
				
			}
			else
			{
				var _vs="," + objvalue[1].decode() + ",";
				for(var j=0;j < objs.length;j++)
				{
					if(_vs.indexOf("," + objs[j].value + ",")>-1)
					{
						objs[j].checked=true;
					}
					else
					{
						objs[j].checked=false;
					}
				}
			}
		}
	}
	
	if(!cancelclose && parent.arrLayerIndex.length>0)
	{
		parent.layer.close(parent.arrLayerIndex.pop());
	}
};
//ajax打开其他模块添加数据
function ajaxOpenModel(url,title,width,height)
{
	var _reload=true;
	var idx=parent.layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: title,
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	  //area : ['800px' , '520px'],
	  //area: [width,height],
	  area:IsMobile() ? ['95%','95%'] : [width,height],    
      //content: [url,'no'],
	  scrollbar: true, 
	  content: [url],
	  success: function(layero, index){
		  parent.arrLayerIndex.push(index);
		  //alert(index);
		  //alert(layero);
	  	  //window[layero.find('iframe')[0]['name']].focus();
	  	  var iframeWin = window[layero.find('iframe')[0]['name']];
		  //alert(iframeWin.document.location.href);
	  	  var act=iframeWin.document.location.href.getquerystring("act");
		  //alert(act);
		  if(act=="view"){_reload=false;}
	  },
	  cancel: function(index, layero){parent.arrLayerIndex.pop();},
	  end : function(index){
		  	if(uploadTempFile.length>0)
			{
				removefile(uploadTempFile);
				uploadTempFile="";
			}
		  if(_reload){document.location.assign(document.location.href);}
		  parent.arrLayerIndex.pop();		  
	  }
    });
};
function OpenFillSelectDlg(modelID,title,width,height,area,fmodelID,clientMode)
{
	var src=getEventObject();
	form_area=$(src).parents("table:first").parent();	
	var url= virtualPath + "Plugins/FillSelectData.aspx?modelid=" + modelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "");
	//if(query.length>0){url+=query;}
	if(document.location.href.getquerystring("debug")) {url+="&debug=1";}
	if(area){url+="&area=" + area;}
	var query="";
	if(typeof(OpenFillSelectDlg_before)=="function")
	{
		var _back=OpenFillSelectDlg_before(modelID);
		if(typeof(_back)=="object")
		{
			//if(!_back.result){return;}
			query=_back.query.replace("?","");
			if(query.length>0)
			{
				//if(query.indexOf("&")!=0){query="&" + query;}			
			}
			var arr=query.split("&");
			for(var x=0;x<arr.length;x++)
			{
				var arr2=arr[x].split("=");
				if(arr2.length==2)
				{
					url=url.addquerystring(arr2[0],arr2[1]);
				}
			}	
		}
	}
	
	if(fmodelID){url+="&fmodelID=" + fmodelID;}
	if(clientMode){url+="&clientMode=" + clientMode;}
	url+= "&t=" + now();
	//alert(url);
	//return;
	
	var idx=layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: title,
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	    //area : ['800px' , '520px'],
	  //area: [width,height],
	  area:IsMobile() ? ['95%','95%'] : [width,height],    
      content: url,
	  success: function(layero, index){arrLayerIndex.push(index);
	  window[layero.find('iframe')[0]['name']].focus();
	  //var iframeWin = window[layero.find('iframe')[0]['name']];
	  },
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){
		  if(typeof(OpenFillSelectDlg_finsh)=="function"){OpenFillSelectDlg_finsh(modelID);}
		  if(typeof(OpenFillSelectDlg_finish)=="function"){OpenFillSelectDlg_finish(modelID);}
		  arrLayerIndex.pop();
	  }
    });
	//alert(idx);
};
//回填窗口
function OpenFillDlg(modelID,title,width,height,area,ptagname,fmodelID,clientMode,obj)
{	
	var src=getEventObject();
	if(obj){src=obj;}
	fillparent=$(src).parents(ptagname+":first")[0];
	//alert($(fillparent).html());
	//return;
	var url= virtualPath + "Plugins/FillData.aspx?modelid=" + modelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "");
	//if(query.length>0){url+=query;}
	var query="";
	if(typeof(OpenFillDlg_before)=="function")
	{
		var _back=OpenFillDlg_before(modelID);//function OpenFillDlg_before(modelid) {return {result:true,query:"s3=3"};  };
		if(typeof(_back)=="object")
		{
			//if(!_back.result){return;}
			query=_back.query.replace("?","");
			if(query.length>0)
			{
				//if(query.indexOf("&")!=0){query="&" + query;}
			}
			var arr=query.split("&");
			for(var x=0;x<arr.length;x++)
			{
				var arr2=arr[x].split("=");
				if(arr2.length==2)
				{
					url=url.addquerystring(arr2[0],arr2[1]);
				}
			}
		}
	}
	if(document.location.href.getquerystring("debug")) {url+="&debug=1";}
	if(area){url+="&area=" + area;}
	if(fmodelID){url+="&fmodelID=" + fmodelID;}
	if(clientMode){url+="&clientMode=" + clientMode;}
	url+= "&t=" + now();
	//alert(url);
	layer.open({
      type: 2,
	  skin: 'layui-layer-rim', //加上边框
      title: title,
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
	    //area : ['800px' , '520px'],
	  //area: [width,height],
	  area:IsMobile() ? ['95%','95%'] : [width,height],    
      content: url,
	  success: function(layero, index){arrLayerIndex.push(index);},
	  cancel: function(index, layero){arrLayerIndex.pop();},
	  end : function(index){
		  if(typeof(OpenFillDlg_finsh)=="function"){OpenFillDlg_finsh(modelID);}
		  if(typeof(OpenFillDlg_finish)=="function"){OpenFillDlg_finish(modelID);}
		  arrLayerIndex.pop();
	  }
    });

	/*
	$.ajax({
			type: 'get',
			url: url,	
			dataType: "html",
			success: function(data)
			{
				alert(data);
			}
		});
	*/
};
function bindzoomImage(obj)
{
	var img=obj.getElementsByTagName("img")[0];
	var layer = $(img).parent().parent().parent();
	var content = $(img).parent().parent();
	var pdiv= $(img).parent();
	var nwidth=0;
	var nheight=0;
			
	if (typeof obj.onmousewheel == "object")
	{
		
	    obj.onmousewheel = function(e)
		{
			var e=e||event,v=e.wheelDelta||e.detail;
			if(v>0)
			{				
				nwidth=$(img).width()*1.05;
				nheight=$(img).height()*1.05;		
			}
			else
			{				
				nwidth=$(img).width()*0.95;
				nheight=$(img).height()*0.95;	
			}
			layer.width(nwidth+20).height(nheight+20).css("top",parseInt(($(document.body).height()-nheight-20)/2) + "px").css("left",parseInt(($(document.body).width()-nwidth-20)/2) + "px");
			content.width(nwidth+20).height(nheight+20);
			pdiv.width(nwidth).height(nheight);
			$(img).width(nwidth).height(nheight);
		};
	}
	else
	{
		obj.addEventListener("DOMMouseScroll",function(e){
			var e=e||event,v=e.wheelDelta||e.detail; 			
			if(v>0)
			{
				nwidth=$(img).width()*0.95;
				nheight=$(img).height()*0.95;
			}
			else
			{
				nwidth=$(img).width()*1.05;
				nheight=$(img).height()*1.05;
			}
			layer.width(nwidth+20).height(nheight+20).css("top",parseInt(($(document.body).height()-nheight-20)/2) + "px").css("left",parseInt(($(document.body).width()-nwidth-20)/2) + "px");
			content.width(nwidth+20).height(nheight+20);
			pdiv.width(nwidth).height(nheight);
			$(img).width(nwidth).height(nheight);
		},false);
	}
	
	setTimeout(function(){
		//alert($(img).height());
		nwidth=$(img).width();
		nheight=$(img).height();
		layer.width(nwidth+20).height(nheight+20).css("top",parseInt(($(document.body).height()-nheight-20)/2) + "px").css("left",parseInt(($(document.body).width()-nwidth-20)/2) + "px");
			content.height(nheight+20);
			pdiv.height(nheight);
		
	},50);
};

function viewImage2(src,w,h)
{
	
	var ieVer = 0;
	var isIE =  window.navigator.userAgent.indexOf("compatible") > -1 &&  window.navigator.userAgent.indexOf("MSIE") > -1;
	if(isIE)
	{
		var reg = new RegExp("MSIE (\\d+\\.\\d+);");
		reg.test(window.navigator.userAgent);
		ieVer = parseFloat(RegExp["$1"]);
	}
	var maxw= 1000;//screen.width - 200;
	if(w>maxw)
	{
		var bl=w/maxw;
		w=maxw;
		h=parseInt(h/bl);
	}

	var html='<div id="viewImagediv" style="padding:10px;overflow:hidden;position:relative;width:' + w + 'px;height:' + h + 'px;"><img onclick="layer.close(layer.index);" id="viewimage" src="' + src + '" width="'+ w +'"></div>';	
	if(IsMobile())
	{

		html='<div id="viewImagediv" style="padding:10px;ov4erflow:hidden;position:relative;width:90%;height:90%;max-width:90%;max-height:90%;text-align:center;"><img onclick="layer.close(layer.index);" id="viewimage" src="' + src + '" style="min-width:50%;min-height:50%;max-width:95%;max-height:95%;display:inline-block;"></div>';	
	}
	layer.open({
  	type: 1
	,area:IsMobile() ? ['100%','100%'] : [(w+20) + 'px',(h+20) + 'px']
	//,shade: 0.2 //透明度
  	,title: false //不显示标题
	,closeBtn: 0
	,scrollbar: false
	,anim: (isIE && ieVer < 9 ? -1 : 4) //0-6的动画形式，-1不开启 IE9以下不支持动画
	,shadeClose: true //开启遮罩关闭
	//,content:'<div style="padding:10px;"><img src="' + src + '" width="'+ w +'"></div'
  	,content:html
	,success: function(layero, index)
	{
		var obj=getobj("viewImagediv");
		bindzoomImage(obj);
		
		setTimeout(function(){ document.focus();},1000);
		arrLayerIndex.push(index);
  	}
	,cancel: function(index, layero){arrLayerIndex.pop();}
	,end : function(index){arrLayerIndex.pop();}
	
	});
};
//新加
function showimg(url)
    {
        layer.open({
            type: 1,
            area: ['90%','90%'],
            shadeClose: true, //开启遮罩关闭
            title: false, //不显示标题
            content: '<img onclick="layer.close(layer.index);" src="' + url + '" style="max-width:100%;max-height:100%;" />', 
            cancel: function () {
            }
        });
    };
function viewImage(src,w,h)
{
	
	
	 var img = new Image(); //图片预加载
	 img.src=src;
	 if(img.complete)
	 {
		 show_Image(img,src);
     }
	 else
	 {
		 img.onload = function()
		 {
			 show_Image(img,src);
		 };
     }	  
};
function show_Image(img,url)
{
	var ieVer = 0;
	var isIE =  window.navigator.userAgent.indexOf("compatible") > -1 &&  window.navigator.userAgent.indexOf("MSIE") > -1;
	if(isIE)
	{
		var reg = new RegExp("MSIE (\\d+\\.\\d+);");
		reg.test(window.navigator.userAgent);
		ieVer = parseFloat(RegExp["$1"]);
	}

         layer.open({
            type: 1,
			title: false, //不显示标题
			closeBtn: 0,
			scrollbar: false,
			shadeClose: true, //开启遮罩关闭
			anim: (isIE && ieVer < 9 ? -1 : 4), //0-6的动画形式，-1不开启 IE9以下不支持动画
            //skin: 'layui-layer-rim', //加上边框
			skin: 'layui-layer-nobg', //没有背景色
           // area: [img.width + 'px', img.height + 'px'], //宽高
		    area: ['auto'],
            content: '<div style="font-size:0px;text-align: center;overflow:hidden;"><img onclick="layer.close(layer.index);" src='+url+' style="max-width:90%;max-height:90%;" /></div>'
         });

};
function viewImage1(src,w,h)
{
	
	var ieVer = 0;
	var isIE =  window.navigator.userAgent.indexOf("compatible") > -1 &&  window.navigator.userAgent.indexOf("MSIE") > -1;
	if(isIE)
	{
		var reg = new RegExp("MSIE (\\d+\\.\\d+);");
		reg.test(window.navigator.userAgent);
		ieVer = parseFloat(RegExp["$1"]);
	}
	var maxw= 1000;//screen.width - 200;
	if(w>maxw)
	{
		var bl=w/maxw;
		w=maxw;
		h=parseInt(h/bl);
	}
	layer.open({
  	type: 1
	//,area:[(w+20) + 'px',(h+20) + 'px']
	//,area: ['90%','90%']
	//,shade: 0.2 //透明度
	,area: ['auto']
  	,title: false //不显示标题
	,skin: 'layui-layer-nobg' //没有背景色
	,closeBtn: 0
	,anim: (isIE && ieVer < 9 ? -1 : 4) //0-6的动画形式，-1不开启 IE9以下不支持动画
	,shadeClose: true //开启遮罩关闭
  	//,content:'<div style="padding:10px;font-size:0px;"><img src="' + src + '" style="display:block;max-width:90%;max-height:90%;"></div>'
	,content:'<img onclick="layer.close(layer.index);" src="' + src + '" style="display:block;max-width:90%;max-height:90%;">'
	,success: function(layero, index)
	{
		setTimeout(function(){ document.focus();},1000);
		arrLayerIndex.push(index);
  	}
	,cancel: function(index, layero){arrLayerIndex.pop();}
	,end : function(index){arrLayerIndex.pop();}
	
	});
};

//新增加
function fill_checkbox(viewid,pid,objid)
{
	
	var url= virtualPath + "Plugins/getData.ashx?viewid=" + viewid + "&pid=" + pid;
	var box=$("#"+ objid + "_box");
	box.html("");
	
	$.ajax({
	type: "GET",
	async: false,
	url: url,
	dataType: "json",
	success: function(data)
	{
		//alert(JSON.stringify(data));

		 $.each(data, function(i,v)
		 {
			 //alert(i + "::" + v["value"] + "::" + this["text"]);
			box.append('<input etype="checkbox" type="checkbox" name="' + objid + '" id="' + objid + '_' + (i+1) + '" value="'+ this["value"] +'" text="'+ this["text"] +'"><label for="' + objid + '_' + (i+1) + '">'+ this["text"] +'</label>'); 
		 });

	}
	});
	
};
//加载数据到下拉框
function FillSelect(objId,Prars,Pid)
{	
	var url= virtualPath + "Plugins/getData.ashx?Pid=" + Pid;	
	if(typeof(AppItem)=="string" && AppItem.length > 0)
	{
		url=url.addquerystring("AppItem",AppItem);
	}
	else
	{
		if(typeof(ModelID)=="string" && ModelID.length > 0){url=url.addquerystring("ModelID",ModelID);}	
	}
	if(Prars.indexOf("&")!=0){url += "&";}
	url += Prars;	
	url += "&t=" + now(),

	$.ajax({
	type: "GET",
	async: false,
	url: url,
	dataType: "json",
	success: function(data)
	{
		//alert(JSON.stringify(data));
		$("#" + objId).get(0).length=1;
		if(!data){return;}
		//$("#" + ObjID).empty();
		 $.each(data, function()
		 {
			$("#" + objId).append('<option value="' + this["value"] + '">' + this["text"] + '</option>'); 
		 });
	}
	});
};
function form_view(obj,ModelID,title,width,height,ID) //自动模块
{
	//if(!ID){ID=obj.getAttribute("eRowID");}
	
	var tr=null;
	if(obj.tagName=="TR" && obj.getAttribute("eRowID")!=null)
	{
		tr=obj;
	}
	else
	{
		tr=getParent(obj.parentNode,"tr");
		if(tr.getAttribute("eRowID")==null){tr=getParent(tr.parentNode,"tr"); }
	}
	if(tr.getAttribute("eRowID")==null){return;}
	if(!ID){ID=tr.getAttribute("eRowID")};
	
	
	//子模块加载数据，不能有AppItem,AppItem是上级的编号
	//var url="?modelid=" + ModelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "") + "&act=viewsub&id=" + ID;
	//var url="?modelid=" + ModelID + "&act=viewsub&id=" + ID;
	var url="?modelid=" + ModelID + "&act=viewsub&id=" + ID;
	
	var logid=document.location.href.getquerystring("logid");
	if(logid.length>0) url+= "&logid=" + logid; 
	url+= "&t=" + now();
	var html=PostURL(url);
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: true //点击遮罩关闭层
	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['返回']
	,yes: function(index,layero)
	{ 
		arrLayerIndex.pop();
		layer.close(index);
	}	
	,cancel: function(index, layero)
	{
		//document.title="Close";
		arrLayerIndex.pop();
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);
		eDataTable_Init();
		if(typeof(form_view_finsh)=="function"){form_view_finsh(ModelID);}
		if(typeof(form_view_finish)=="function"){form_view_finish(ModelID);}
  	}
	,end : function(index){arrLayerIndex.pop();}
	
	
    });
	
};
function form_ViewN(obj,ModelID,title,width,height,url) //自定义模块
{
	var html=PostURL(url);	
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: true //点击遮罩关闭层
	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['返回']
	,yes: function(index,layero)
	{ 
		arrLayerIndex.pop();
		layer.close(index);
	}	
	,cancel: function(index, layero)
	{
		arrLayerIndex.pop();
		//document.title="Close";
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);		
  	}
	 ,end : function(index){arrLayerIndex.pop();}
	
    });
};
function form_View(obj,ModelID,title,width,height,url) //自定义模块
{
	var html=PostURL(url);	
	//alert(html);
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: true //点击遮罩关闭层
	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['返回']
	,yes: function(index,layero)
	{ 
		arrLayerIndex.pop();
		layer.close(index);
	}	
	,cancel: function(index, layero)
	{
		arrLayerIndex.pop();
		//document.title="Close";
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);		
  	}
	 ,end : function(index){arrLayerIndex.pop();}
	
    });

	var tr= obj; //getParent(obj,"tr");
	var index=tr.Index();
	//alert(index);
	var form=getobj("form_" + ModelID);
	var input=getobj("eformdata_" + ModelID);
	var model=input.value.toJson();
	model=model.get("eformdata_" + ModelID);
	var data=model.get(index);
	data.foreach(function(e)
	{
		if(typeof(data[e])=="object")
		{			

			var ctrl = form[e];			
			//ctrl.value= "{\"" + p + "\":" + data[e].toJson() + "}";
			var node=data[e];			
			//if(!node.append){node=new eJson(node);}
			//node.Convert=true;
			ctrl.value= "{\"" + e + "\":" + node.toJson() + "}";
			JsonToTable(data[e],e.replace("eformdata_","eformlist_"));
		}
		else
		{
			if(e.toLowerCase()=="id"){return;}
			if(e.toLowerCase()=="delete"){return;}
			if(e.indexOf("_Text")>-1){return;}
			var ctrl=document.getElementById("span_" + e);

			
			if(!ctrl){return;}
			if(data[e+"_Text"])
			{
				ctrl.innerHTML=data[e+"_Text"].decode();
			}
			else
			{				
				ctrl.innerHTML=data[e].decode();
			}
			//alert(e);
		}
	});
	eDataTable_Init();
};
function Check_CheckUp()
{
	var tr=getobj("checkup_trback");
	if(tr)
	{		
		//tr.style.display= (frmCheckUp["f1"].value == "1" ? "none" : "");
		if(frmCheckUp["f1"].value == "2")
		{
			tr.style.display = "";
			frmCheckUp["f3"].setAttribute("notnull","true");
		}
		else
		{
			tr.style.display = "none";
			frmCheckUp["f3"].setAttribute("notnull","false");
		}
	}	
};
function CheckUp(UserArea)
{
	var vpath=null;
	var evt=window.event||arguments[0];
	var src=evt.srcElement||evt.target;
	if(src)
	{
		if(src.tagName=="I")
		{
			vpath=src.parentNode.parentNode.getAttribute("vpath");
		}
	}
	var dlgid="";
	var url= (vpath == null ? virtualPath : vpath) + "Customs/base/CheckUp.aspx?UserArea=" + UserArea;	
	if(typeof(AppItem)=="string" && AppItem.length > 0){dlgid=AppItem;url+="&AppItem=" + AppItem;}
	if(typeof(ModelID)=="string" && ModelID.length > 0){dlgid=ModelID;url+="&ModelID=" + ModelID;}	
	url+="&id=" + document.location.href.getquerystring("id");	
	url+="&t=" + now();
	//alert(url);
	//return;
	//window.alert(url);
	$.ajax({
			type: 'get',
			async: false,
			url: url,	
			dataType: "html",
			success: function(data)
			{
				
				//alert(data);
				var json=data.toJson();
			
				//if(parseBool(json.success))
				if(json.errcode=="0")
				{
					var html = json.html.decode();
					
					var _width="600px";
					if(IsMobile()){_width="95%";}
					//alert(json.html.replace(/</gi,"&lt;").replace(/>/gi,"&gt;"));
					layer.open({
					type: 1 //此处以iframe举例
					,title: json.title // + "窗口"
					//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
					,shadeClose: false //点击遮罩关闭层
					//,area: ["500px",json.width + "300px"]
					,area: [_width,json.height + "px"]
					,shade: 0.2 //透明度
					,maxmin: false
					,id: dlgid.replace(/-/gi,"") //设定一个id，防止重复弹出
					,resize: true
					,btnAlign: 'l' //lcr
					,moveType: 0 //拖拽模式，0或者1
					,anim: 0 //0-6的动画形式，-1不开启
					,content: html
					,btn: [json.text, '返回']
					,yes: function(index,layero)
					{
						
					
						var _back=eCheckform(frmCheckUp);							
						if(!_back){return;}
						var _value="";
						if(frmCheckUp.elements["f1"] || frmCheckUp["f1"])
						{						
						 	_value=frmCheckUp["f1"].value || frmCheckUp.elements["f1"].value;
						}
						if( json.title == "审33核" && _value == "1")
						{
							var back_tip=confirm('提示：本人已知晓本次操作会将相应信息发布到互联网，我已确认本次发布信息符合相关安全规定，无涉密内容。');
							if(!back_tip){return;}
						}
						
						//if(_back){arrLayerIndex.pop();layer.close(index);}
						
						//url= $("#frmCheckUp").attr("action");
						url=frmCheckUp.action || $("#frmCheckUp").attr("action");
						url=url.addquerystring("act","checkup");
						if(frmCheckUp["f1"])
						{
							var chk="0";
							if(frmCheckUp["f11"].checked){chk="1";}
							if(frmCheckUp["f12"].checked){chk="2";}
							if(frmCheckUp["f13"].checked){chk="3";}
							url=url.addquerystring("f1",chk);
						}
						if(frmCheckUp["f2"]){url=url.addquerystring("f2",frmCheckUp["f2"].value.encode());}
						if(frmCheckUp["f3"]){url=url.addquerystring("f3",frmCheckUp["f3"].value.encode());}

						if(typeof(AppItem)=="string" && AppItem.length>0){url=url.addquerystring("AppItem",AppItem);}
						if(typeof(eSignIn)==="object")
						{
							var _url = virtualPath + "Plugins/SignIn.aspx?act=checkup";
							if(typeof(AppItem)=="string" && AppItem.length > 0){_url+="&AppItem=" + AppItem;}else{if(typeof(ModelID)=="string" && ModelID.length > 0){_url+="&ModelID=" + ModelID;}}
							var data = eSignIn.getdata();
							if(data.length>100)
							{
								$.ajax({
							        type: 'POST',
									async: false,
							        url: _url,
									data: {"imageData" :  data  },
							        dataType: 'json',
							        success: function (data) {
										if(data.errcode=="0")
										{
											url=url.addquerystring("signfile",data.signfile);
										}
							        }
							    });
							}
						}
						//alert(url);
						//return false;
						$.ajax({
								type: 'get',
								async: false,
								url:url,
								dataType: "json",
								success: function(data)
								{
									//if(parseBool(data.success))
									if(data.errcode=="0")
									{
										url=document.location.href;									
										$.ajax({
											type: 'get',
											async: false,
											url:url,
											dataType: "html",
											success: function(data)
											{												
												//alert(data);
												//layer.msg(json.title + "成功!");
												//setTimeout(function(){document.location.assign(url);},2000);
												var table=data;
												var sstr= '<!--body_start-->';//'<div id="content"';// style="margin:10px;">
												var estr='<!--body_end-->';//'</table>\r\n</div>';
		
												var s=table.indexOf(sstr);
												if(s>-1)
												{
													s+=sstr.length;
													var e=table.indexOf(estr,s);
													if(e>-1)
													{
														
														e+=estr.length;
														$("#content").html(table.substring(s,e) + "");
														layer.msg(json.title + "成功!");
													}
												}
												layer.close(index);
											}
										});										   
									}
								}								
							});
	

				
					}
					,btn2: function(index, layero)
					{
						//document.title="关闭";
						arrLayerIndex.pop();
					}
					,cancel: function(index, layero)
					{
						//document.title="Close";
						arrLayerIndex.pop();
					}
					,success: function(layero, index)
					{
						if(typeof(eSignIn)==="object")//签名插件
						{
							eSignIn.init();
						}	
						arrLayerIndex.push(index);
					}
	  				,end : function(index){arrLayerIndex.pop();}
					});
				}
				else
				{
					layer.msg(json.message);
				}
			}
		});
};
function form_load(ModelID)
{

	var input=getobj("eformdata_" + ModelID);
	
	var model=input.value.toJson();
	model=model.get("eformdata_" + ModelID);
	if(model.length==0){return;}
	var data=model.get(0);
	var form=getobj("form_" + ModelID);
	data.foreach(function(e)
	{
		
		var ctrl = form[e];
		if(!ctrl)
		{
			//if(e.indexOf("_Text")>-1){return;}
			ctrl=document.getElementById("span_" + e);
			if(!ctrl){return;}
			if(ctrl.innerHTML.length>0) {return;}
			
			if(data[e+"_Text"])
			{
				ctrl.innerHTML=data[e+"_Text"].decode();
			}
			else
			{
				ctrl.innerHTML=data[e].decode();
			}
		}
		if(!ctrl){return;}
		
		if(typeof(data[e])=="object")
		{
			var table=getobj(ctrl.name.replace("eformdata_","eformlist_"));
			if(table)
			{
				if(table.getAttribute("reinit")!="false")
				{
					var node=data[e];
					//if(!node.append){node=new eJson(node);}			
					//node.Convert=true;
					//alert(node.tostring());
					ctrl.value="{\"" + e + "\":" + node.toJson() + "}";
					JsonToTable(data[e],e.replace("eformdata_","eformlist_"));
				}
			}
		}
		else
		{
			
			if(typeof(e)=="string")
			{
				if(ctrl.tagName)//一个
				{
					var etype = ctrl.getAttribute("etype");					
					ctrl.value= data[e].decode();
					if(etype=="select")
					{
						if(ctrl.selectedIndex==-1){ctrl.selectedIndex=0;}
					}
					if(etype=="file")
					{
						var frame=getobj("frm" + ctrl.name);
						var url=frame.getAttribute("src");
						if(ctrl.value.length > 0)
						{
							url=url.addquerystring("act","finsh");
							url=url.addquerystring("file",ctrl.value);
						}
						else
						{
							url=url.removequerystring("act");
							url=url.removequerystring("file");
						}
						frame.src=url;
					}
					if(etype=="html")
					{

						KE.html(ctrl.name,data[e].decode());
					}
				}
				else//多个
				{
					var type=Attribute(ctrl[0],"type").toLowerCase();
					var _tmp="," + data[e].decode() + ",";
					for(var i=0;i<ctrl.length;i++)
					{
						if(_tmp.indexOf("," + ctrl[i].value + ",")>-1)
						{
							ctrl[i].checked=true;
						}
					}
				}

			}
		}		
	});	
	eDataTable_Init();
};
function getAddHTMLN(ModelID,_url)
{


	var html="";	
	
	//eval("var modelhtml=window.ModelHTML_" + ModelID + ";");
	var modelhtml=eval("window.ModelHTML_" + ModelID.replace(/-/gi,"") );
	
	if(modelhtml)
	{
		html=modelhtml;
		//document.title="get";
	}
	else
	{
		//var url="?modelid=" + ModelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "")  + "&act=addsub";
		var url=document.location.href;
		url=url.removequerystring("id");
		url=url.removequerystring("act");
		url=url.addquerystring("ModelID",ModelID);
		url=url.addquerystring("act","addsub");
		if(_url){url=_url;}


	
		if(typeof(getAddHTML_before)=="function")
		{
			
			var _back=getAddHTML_before(ModelID);
			if(typeof(_back)=="object")
			{
				//if(!_back.result){return;}
				if(_back.query.length>0)
				{
					//url+= url.indexOf("?") > -1 ? "&" + _back.query : "?"  + _back.query ;
					var query=_back.query.replace("?","");
					var arr=query.split("&");
					for(var x=0;x<arr.length;x++)
					{
						var arr2=arr[x].split("=");
						if(arr2.length==2)
						{
							url=url.addquerystring(arr2[0],arr2[1]);
						}
					}
				}
				
			}
		}
		if(url.indexOf("pid=")==-1)
		{
			var id=document.location.href.getquerystring("id");
			if(id.length>0)
			{
				url+= url.indexOf("?") > -1 ? "&pid=" + id : "?pid="  + id ;
			}
		}
		
		var debug=document.location.href.getquerystring("debug");
		if(debug.length>0) url+= "&debug=" + debug; 
		url+= "&t=" + now();
		html=PostURL(url);
		eval('window.ModelHTML_'+ ModelID.replace(/-/gi,"") +'=html;');
		//document.title="set";
	}
	return html;
};
function form_viewN(obj,ModelID,title,width,height,ID) //自动模块
{
	//if(!ID){ID=obj.getAttribute("eRowID");}
	//alert(obj instanceof jQuery);
	//alert(obj instanceof Array);   //会返回true
	//alert(obj instanceof Object)  
	//alert(typeof(obj));
	var tr=null;
	if(obj.tagName=="TR" && obj.getAttribute("eRowID")!=null)
	{
		tr=obj;
	}
	else
	{
		tr=getParent(obj.parentNode,"tr");
		if(tr.getAttribute("eRowID")==null){tr=getParent(tr.parentNode,"tr"); }
	}
	
	if(tr.getAttribute("eRowID")==null){return;}
	
	if(!ID){ID=tr.getAttribute("eRowID")};
	
		var url=document.location.href;
		url=url.removequerystring("id");
		url=url.removequerystring("act");
		url=url.addquerystring("ModelID",ModelID);
		url=url.addquerystring("act","viewsub");
		url=url.addquerystring("id",ID);
		

	

	
	var logid=document.location.href.getquerystring("logid");
	if(logid.length>0) url+= "&logid=" + logid; 
	url+= "&t=" + now();


	var html=PostURL(url);
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: true //点击遮罩关闭层
	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['返回']
	,yes: function(index,layero)
	{ 
		arrLayerIndex.pop();
		layer.close(index);
	}	
	,cancel: function(index, layero)
	{
		//document.title="Close";
		arrLayerIndex.pop();
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);
		eDataTable_Init();
		if(typeof(form_view_finsh)=="function"){form_view_finsh(ModelID);}
		if(typeof(form_view_finish)=="function"){form_view_finish(ModelID);}
  	}
	,end : function(index){arrLayerIndex.pop();}
	
	
    });
	
};
var form_area;//保存区域对象Jquery对象
function form_saveN(ModelID)
{
	
	var frm= document.forms["form_" + ModelID];
	if(!frm){alert("表单form_" + ModelID + "不存在!");return false;}	
	var Prefix="M" + ModelID + "_";
	Prefix="";

	var _back=eCheckform(frm);	
	if(!_back){return false;}

	
	//var input=getobj("eformdata_" + ModelID);
	var input;
	if(form_area)
	{
		input=form_area.find("#eformdata_" + ModelID);		
		input=input.length>0 ? input[0] : getobj("eformdata_" + ModelID);
	}
	else
	{
		input=getobj("eformdata_" + ModelID);
	}
	//alert(input);
	//input.style.borderColor="#ff0000";
	//return true;
	var model=input.value.toJson();	
	//model.Convert=true;
	//alert(model.toJson());
	
	var _data=model.get("eformdata_" + ModelID);
	

	var index=parseInt(frm[Prefix + "Index"].value);
	
	
	//var table=getobj("eformlist_" + ModelID);
	var table;
	if(form_area)
	{
		table=form_area.find("#eformlist_" + ModelID);
		table=table.length>0 ? table[0] : getobj("eformlist_" + ModelID);
	}
	else
	{
		table=getobj("eformlist_" + ModelID);
	}
	
	
	var tbody=table.getElementsByTagName("tbody")[0];
	var obj= formToJson(frm);
	//alert("form_SaveN" + obj.toJson());
	//return;
	//alert(new eJson(obj).toJson());
	

	//return;
	
	var tfoot=table.getElementsByTagName("tfoot")[0];
	var otr=tfoot.getElementsByTagName("tr")[0].cloneNode(true);
	var otds=otr.getElementsByTagName("td");
	if(index>-1)//替换
	{
		_data[index]=obj;
		
		//var tr=tbody.getElementsByTagName("tr")[index];
		var tr=tbody.children[index];
		//tr,td 不可以使用getElementsByName  getElementById 所以要从TD 去读JSON数据，而不是从Json数据到TD
		//alert(tr.outerHTML);
		
		
		 $(tr).find("[name]").each(function(i,elem){
			var name=elem.getAttribute("name");
			if(name)
			{
				var _opar= $(otr).find("[name='" + name + "']").get(0);
				name=name.replace("td_","");
				if(obj[name+"_Text"])
				{
					elem.innerHTML=obj[name+"_Text"].decode();
				}
				else
				{
					if(obj[name])
					{
						
						if(_opar.innerHTML.toLowerCase().indexOf("data:")==-1)
						{
							elem.innerHTML=obj[name].decode();
						}
						else
						{
							elem.innerHTML=_opar.innerHTML.replace(/{data:.*?}/gi,obj[name].decode());
						}
						
					}
					else
					{
						if(name.length>0 && _opar.innerHTML.toLowerCase().indexOf("data:")> -1){elem.innerHTML="";}
					}
				}
			}
	     });
	}
	else //添加
	{
		_data.append(obj);

		$(otr).find("[name]").each(function(i,elem){
			var name=elem.getAttribute("name");
			if(name)
			{
				name=name.replace("td_","");
				if(obj[name+"_Text"])
				{
					elem.innerHTML=obj[name+"_Text"].decode();				
				}
				else
				{
					if(obj[name])
					{
						if(elem.innerHTML.toLowerCase().indexOf("data:")==-1)
						{
							elem.innerHTML=obj[name].decode();
						}
						else
						{
							elem.innerHTML=elem.innerHTML.replace(/{data:.*?}/gi,obj[name].decode());
						}
						
					}
					else
					{
						//elem.innerHTML="";
						//alert($(tbody).find("tr").length);
						//更新顺序号
						elem.innerHTML=elem.innerHTML.replace(/{row:index}/gi,$(tbody).children("tr").length + 1);
					}
				}
			}
		});		
		tbody.appendChild(otr);
		//alert(table.parent);
		if(table.parent){Table_Init_Tbody(table.parent);}
		
	}
	//alert(model.toJson());
	input.value=model.toJson();
	//form_cancel(ModelID);
	//var count=getobj("count_" + ModelID);
	var count;
	if(form_area)
	{
		count=form_area.find("#count_" + ModelID);
		count=count.length>0 ? count[0] : count=getobj("count_" + ModelID);
	}
	else
	{
		count=getobj("count_" + ModelID);
	}
	//alert(count);
	if(count)
	{
		count.value=$(tbody).find("tr:visible").length;// tbody.children.length;
	}
	//回调函数-添加修改
	if(typeof(submodel_onChange)=="function")
	{
		var list_trs=$("#eformlist_" + ModelID + " tbody tr");
		submodel_onChange(ModelID,list_trs,tbody);
	}

	return true;
};
function form_addN(obj,ModelID,title,width,height,url)
{
	form_area=$(obj).parents("table:first").parent();
	//form_area[0].style.borderColor="#ff0000";
	//alert(form_area[0].tagName);
	var html=getAddHTMLN(ModelID,url);
	//alert(html);
	//return;
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: false //点击遮罩关闭层
  	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['确定', '关闭']
	,yes: function(index,layero)
	{ 
		//alert(ModelID);

		var _back=form_saveN(ModelID);
		if(_back){arrLayerIndex.pop();layer.close(index);}
	}
	,btn2: function(index, layero)
	{
		//document.title="关闭";
		arrLayerIndex.pop();
	}
	,cancel: function(index, layero)
	{
		//document.title="Close";
		arrLayerIndex.pop();
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);
		$('.layui-layer-content textarea[etype*="html"]').each(function(i,elem){
			KE.init({
				id : elem,
				width :  elem.getAttribute("width") ,
				height : elem.getAttribute("height")
			});
			KE.create(elem.id);
		});
		initdate($('.layui-layer-content'));//初始化移动端日期选择
		if(typeof(form_add_finsh)=="function"){form_add_finsh(ModelID);}
		if(typeof(form_add_finish)=="function"){form_add_finish(ModelID);}
  	}
	 ,end : function(index){arrLayerIndex.pop();}
    });
	var form=getobj("form_" + ModelID);	
	if(form){form["Index"].value="-1";}
};
function JsonToDD(data,dd)
{

	data.foreach(function(e)
	{
		var ctrl= dd.find("[postname='" + e + "']");
		if(ctrl.length>0)
		{
			/*
			var type=ctrl.attr("type").toLowerCase();
			if(type=="checkbox" || type=="radio")//只有一个选项
			{
				var _tmp="," + data[e].decode() + ",";
				if(_tmp.indexOf("," + ctrl.value + ",")>-1)
				{
					ctrl.checked=true;
				}
			}
			else
			{
				ctrl.val(data[e]);
			}
			*/
			ctrl.each(function(i,el){
				var type=ctrl.attr("type").toLowerCase();
				if(type=="checkbox" || type=="radio")//只有一个选项
				{
					var _tmp="," + data[e].decode() + ",";
					if(_tmp.indexOf("," + el.value + ",")>-1)
					{
						el.checked=true;
					}
				}
				else
				{
					$(this).val(data[e]);
				}
			});	
		}
	});
};
function form_editN(obj,ModelID,title,width,height,url)
{
	var src=getEventObject();
	if(src.tagName.toLowerCase()=="a" && src.className=="btndel"){return;}
	form_area=$(obj).parents("table:first").parent();
	var Prefix="M" + ModelID + "_";
	Prefix="";

	var rect=obj.getBoundingClientRect();	
	var html=getAddHTMLN(ModelID,url);

	
	//var frm=new eDialog("model_form_" + ModelID.replace(/-/gi,""),"修改",rect.left,Scroll().top + rect.bottom,500,300);
	//frm.setHTML(html);
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: false //点击遮罩关闭层
	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['确定', '关闭']
	,yes: function(index,layero)
	{ 
		var _back=form_saveN(ModelID);
		if(_back){arrLayerIndex.pop();layer.close(index);}
	}
	,btn2: function(index, layero)
	{
		arrLayerIndex.pop();
		//document.title="关闭";
	}
	,cancel: function(index, layero)
	{
		arrLayerIndex.pop();
		//document.title="Close";
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);
		$('.layui-layer-content textarea[etype*="html"]').each(function(i,elem){
			//弹出层有问题
			KE.init({
				id : elem,
				width :  elem.getAttribute("width") ,
				height : elem.getAttribute("height")
			});
			KE.create(elem.id);
			//KE.html(elem.id, '<h3>Hello KindEditor</h3>');

		});
		initdate($('.layui-layer-content'));
		if(typeof(form_edit_finsh)=="function"){form_edit_finsh(ModelID);}
		if(typeof(form_edit_finish)=="function"){form_edit_finish(ModelID);}
  	}
	  ,end : function(index){arrLayerIndex.pop();}

    });
	
	

	
	//var tr=obj;//getParent(obj,"tr");
	//var index=0;
	//for(i=0;i<trs.length;i++){if(trs[i]== tr){index= i;}}
	var tr=null;

	if(obj.tagName=="TR" && obj.getAttribute("eRowID")!=null)
	{
		tr=obj;
	}
	else
	{
		tr=getParent(obj.parentNode,"tr");

	}
	

	if(tr.getAttribute("eRowID")==null)
	{
		tr=getParent(tr,"tr");
	}

	var index=tr.Index();
	//alert(index);
	var form=getobj("form_" + ModelID);
	if(form[Prefix + "Index"])
	{
		form[Prefix + "Index"].value=index;
	}
	
	//alert(form.elements.length);
	for(i=0; i < form.elements.length; i++)
	{
		//alert(form.elements[i].name);
	}
	//var input=getobj("eformdata_" + ModelID);
	var input;
	if(form_area)
	{
		input=form_area.find("#eformdata_" + ModelID);		
		input=input.length>0 ? input[0] : getobj("eformdata_" + ModelID);
	}
	else
	{
		input=getobj("eformdata_" + ModelID);
	}
	
	
	
	var model=input.value.toJson();
	//alert(model.toJson());
	//model.Convert=true;	
	model=model.get("eformdata_" + ModelID)	
	//alert(ModelID + "::" + model.toJson());
	var data=model.get(index);	
	//alert(data.toJson());
	//alert(index);
	//alert(data.foreach);
	data.foreach(function(e)
	{
		//alert(e);
		var ctrl = form[e];		
		//alert(e + "::" + ctrl.length);
		if(!ctrl){return;}
		if(ctrl.length && (e.toLowerCase()=="id" || e.toLowerCase()=="delete"))
		{
			ctrl=ctrl[0];//excel会造成ID，delete多个
		}
		if(typeof(data[e])=="object")
		{
			
			var node=data[e];		
			//alert(node.toJson());
			//if(!node.append){node=new eJson(node);}
			//node.Convert=true;
			ctrl.value= "{\"" + e + "\":" + node.toJson() + "}";
			
			var par=$(ctrl).parent();
			var listobj= par.find("#" + e.replace("eformdata_","eformlist_"));
			if(listobj.length>0 && listobj.attr("class")=="divsubList")
			{
				var _modelid= e.replace("eformdata_","");
				var _html=getAddHTMLN(_modelid);					
				node.foreach(function(x)
				{
					listobj.append(_html);
					var dd=listobj.find("dl:last dd");
					JsonToDD(node[x],dd);
				});
			}
			else
			{
				//JsonToTable(data[e],e.replace("eformdata_","eformlist_"));
				JsonToTable(node,e.replace("eformdata_","eformlist_"));
			}
		}
		else
		{
		
			if(typeof(e)=="string")
			{
				
				if(ctrl.tagName)
				{
					//alert(ctrl.tagName + "::" + ctrl.name + "::" +  data[e]);
					
					var type=Attribute(ctrl,"type").toLowerCase();
					if(type=="checkbox" || type=="radio")//只有一个选项
					{
						var _tmp="," + data[e].decode() + ",";
						if(_tmp.indexOf("," + ctrl.value + ",")>-1)
						{
							ctrl.checked=true;
						}
						return;
						//alert(e + "::" + ctrl.tagName + "::" + ctrl.length + "::" + type);
					}				
					var v=data[e].decode();
					ctrl.value= v;
					ctrl.setAttribute("ovalue",v);

					var editreadonly=Attribute(ctrl,"editreadonly");
					if(v.length>0 && editreadonly=="true")
					{
						ctrl.setAttribute("readOnly","true");
					}

					if(ctrl.onchange)
					{
						$(ctrl).trigger("change");
					}
					var etype=Attribute(ctrl,"etype").toLowerCase();
					if(etype=="singleuser" && ctrl.value.length>0 && ctrl.name.toLowerCase().indexOf("_text")>-1)
					{
						//alert($(ctrl).parent().text() + "::" + ctrl.value + "::" + ctrl.name  );
						$(ctrl).parent().find("p").text(ctrl.value);
					}
					if(etype=="label" && ctrl.value.length>0)
					{
						var onext = ctrl.nextElementSibling||ctrl.nextSibling;						
						onext.innerHTML=ctrl.value;
					}
					if(etype=="html" && ctrl.value.length>0)
					{
						KE.html(ctrl.id, ctrl.value);
						//alert(etype + "::" + ctrl.value + "::" + ctrl.id);
					}
					//alert(etype + "::" + ctrl.value);
					if(etype=="file" && ctrl.value.length>0)
					{
						var frame=getobj("frm" + ctrl.id );
						if(frame)
						{
							var src=frame.getAttribute("src");
							if(src.toLowerCase().indexOf("act=")==-1)
							{
								src+="&act=finsh";
							}
							src+="&file=" + ctrl.value;
							//alert(src);
							//alert(ctrl.id + "::" + data[e]);
							frame.src=src;
						}
					}
				}
				else
				{
					//checkbox or radio
					var type=Attribute(ctrl[0],"type").toLowerCase();
					var editreadonly=Attribute(ctrl[0],"editreadonly");					
					var _tmp="," + data[e].decode().toLowerCase().replace("true","1").replace("false","0") + ",";
					//alert(type + "::" + _tmp);
					for(var i=0;i<ctrl.length;i++)
					{
						if(editreadonly=="true")
						{
							//ctrl[i].setAttribute("readOnly","true");
							ctrl[i].disabled=true;
						}
						if(_tmp.indexOf("," + ctrl[i].value.toLowerCase().replace("true","1").replace("false","0") + ",")>-1)
						{
							ctrl[i].checked=true;
						}
					}
				}
			}
		}
	});
	
	eDataTable_Init();
};
function form_deleteN(obj,ModelID,delText)
{
	if(!delText){delText="删除";}
	var Prefix="M" + ModelID + "_";
	Prefix="";
	if(!confirm("确认要" + delText + "吗？")){return;}
	
	var tr=getParent(obj,"tr");
	if(tr.getAttribute("eRowID")==null)
	{
		tr=getParent(tr.parentNode,"tr");
	}
	//alert(tr.getAttribute("eRowID"));
	//return;
	var tbody=getParent(tr,"tbody");
	var trs=tbody.getElementsByTagName("tr");
	//var index=0;
	//for(i=0;i<trs.length;i++){if(trs[i]== tr){index= i;}}
	var index=tr.Index();
	
	var input=getobj("eformdata_" + ModelID);
	
	var model=input.value.toJson();
	//model.Convert=true;

	
	var _model=model.get("eformdata_" + ModelID);
	_model=_model[index];

	if(_model[Prefix + "ID"].length==0)
	{
		_model=model.get("eformdata_" + ModelID)
		_model.remove(index);	
		tbody.removeChild(tr);
	}
	else
	{
		_model[Prefix + "Delete"]="true";
		tr.style.display="none";
	}
	//更新顺序号
	var otable=getobj("eformlist_" + ModelID);	
	var otfoot=otable.getElementsByTagName("tfoot")[0];
	var otr=otfoot.getElementsByTagName("tr")[0].cloneNode(true);
	var otds=otr.getElementsByTagName("td");
	var row_index=-1;
	for(var i=0;i<otds.length;i++)
	{
		if(otds[i].innerHTML.toLowerCase().indexOf("row:index")>-1)
		{
			row_index=i;
			break;
		}
	}
	if(row_index>-1)
	{
		$(tbody).find("tr:visible").each(function(i,elem){
			$(this).find("td:eq(" + row_index + ")").html(i + 1); 
		});
	}
		
	//var count=getobj("count_" + ModelID);
	var count;
	if(form_area)
	{
		count=form_area.find("#count_" + ModelID);
		count=count.length>0 ? count[0] : count=getobj("count_" + ModelID);
	}
	else
	{
		count=getobj("count_" + ModelID);
	}
	
	if(count)
	{		
		count.value= $(tbody).find("tr:visible").length;// tbody.children.length;
	}
	input.value=model.toJson();	

	//回调函数-删除
	if(typeof(submodel_onChange)=="function")
	{
		var list_trs=$("#eformlist_" + ModelID + " tbody tr");
		submodel_onChange(ModelID,list_trs,tbody);
	}
};
//OK
function form_add(obj,ModelID,title,width,height,url)
{
	
	var html=getAddHTML(ModelID,url);
	//alert(html);
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: false //点击遮罩关闭层
  	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['确定', '关闭']
	,yes: function(index,layero)
	{ 
		var _back=form_save(ModelID);
		if(_back){arrLayerIndex.pop();layer.close(index);}
	}
	,btn2: function(index, layero)
	{
		//document.title="关闭";
		arrLayerIndex.pop();
	}
	,cancel: function(index, layero)
	{
		//document.title="Close";
		arrLayerIndex.pop();
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);
		$('.layui-layer-content textarea[etype*="html"]').each(function(i,elem){
			KE.init({
				id : elem,
				width :  elem.getAttribute("width") ,
				height : elem.getAttribute("height")
			});
			KE.create(elem.id);
		});
		initdate($('.layui-layer-content'));//初始化移动端日期选择
		if(typeof(form_add_finsh)=="function"){form_add_finsh(ModelID);}
		if(typeof(form_add_finish)=="function"){form_add_finish(ModelID);}
  	}
	 ,end : function(index){arrLayerIndex.pop();}
    });
	
	var form=getobj("form_" + ModelID);	
	if(form){form["Index"].value="-1";}
};
//OK

function form_edit(obj,ModelID,title,width,height,url)
{
	
	var src=getEventObject();
	if(src.tagName.toLowerCase()=="a" && src.className=="btndel"){return;}
	//alert(ModelID);
	var Prefix="M" + ModelID + "_";
	Prefix="";

	var rect=obj.getBoundingClientRect();	
	var html=getAddHTML(ModelID,url);
	//alert(html);

	
	//var frm=new eDialog("model_form_" + ModelID.replace(/-/gi,""),"修改",rect.left,Scroll().top + rect.bottom,500,300);
	//frm.setHTML(html);
	layer.open({
  	type: 1 //此处以iframe举例
  	,title: title
	//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
	,shadeClose: false //点击遮罩关闭层
	,area: IsMobile() ? ['98%',height] : [width,height]
	,shade: 0.2 //透明度
	,maxmin: false
	,id: ModelID.replace(/-/gi,"") //设定一个id，防止重复弹出
	,resize: true
	,btnAlign: 'l' //lcr
	,moveType: 0 //拖拽模式，0或者1
	,anim: 0 //0-6的动画形式，-1不开启
	,content: html
	,btn: ['确定', '关闭']
	,yes: function(index,layero)
	{ 
		var _back=form_save(ModelID);
		if(_back){arrLayerIndex.pop();layer.close(index);}
	}
	,btn2: function(index, layero)
	{
		arrLayerIndex.pop();
		//document.title="关闭";
	}
	,cancel: function(index, layero)
	{
		arrLayerIndex.pop();
		//document.title="Close";
	}
	,success: function(layero, index)
	{
		arrLayerIndex.push(index);
		$('.layui-layer-content textarea[etype*="html"]').each(function(i,elem){
			//弹出层有问题
			KE.init({
				id : elem,
				width :  elem.getAttribute("width") ,
				height : elem.getAttribute("height")
			});
			KE.create(elem.id);
			//KE.html(elem.id, '<h3>Hello KindEditor</h3>');

		});
		initdate($('.layui-layer-content'));
		if(typeof(form_edit_finsh)=="function"){form_edit_finsh(ModelID);}
		if(typeof(form_edit_finish)=="function"){form_edit_finish(ModelID);}
  	}
	  ,end : function(index){arrLayerIndex.pop();}

    });
	
	
	
	//var tr=obj;//getParent(obj,"tr");
	//var index=0;
	//for(i=0;i<trs.length;i++){if(trs[i]== tr){index= i;}}
	var tr=null;

	if(obj.tagName=="TR" && obj.getAttribute("eRowID")!=null)
	{
		tr=obj;
	}
	else
	{
		tr=getParent(obj.parentNode,"tr");

	}	

	if(tr.getAttribute("eRowID")==null)
	{
		tr=getParent(tr,"tr");
	}

	var index=tr.Index();
	//alert(index);
	var form=getobj("form_" + ModelID);
	if(form[Prefix + "Index"])
	{
		form[Prefix + "Index"].value=index;
	}
	
	var input=getobj("eformdata_" + ModelID);
	var model=input.value.toJson();
	//model.Convert=true;	
	model=model.get("eformdata_" + ModelID)	
	var data=model.get(index);	
	//alert(index);
	data.foreach(function(e)
	{
		var ctrl = form[e];		
		if(!ctrl){return;}		
		if(typeof(data[e])=="object")
		{
			var node=data[e];			
			//if(!node.append){node=new eJson(node);}
			//node.Convert=true;
			ctrl.value= "{\"" + e + "\":" + node.toJson() + "}";
			//alert(node.toJson());
			JsonToTable(data[e],e.replace("eformdata_","eformlist_"));
		}		
		else
		{
		
			if(typeof(e)=="string")
			{
				
				if(ctrl.tagName)
				{
					var type=Attribute(ctrl,"type").toLowerCase();
					if(type=="checkbox" || type=="radio")//只有一个选项
					{
						var _tmp="," + data[e].decode() + ",";
						if(_tmp.indexOf("," + ctrl.value + ",")>-1)
						{
							ctrl.checked=true;
						}
						return;
						//alert(e + "::" + ctrl.tagName + "::" + ctrl.length + "::" + type);
					}				
					ctrl.value= data[e].decode();					
					if(ctrl.onchange)
					{
						$(ctrl).trigger("change");
					}
					var etype=Attribute(ctrl,"etype").toLowerCase();
					if(etype=="singleuser" && ctrl.value.length>0 && ctrl.name.toLowerCase().indexOf("_text")>-1)
					{
						//alert($(ctrl).parent().text() + "::" + ctrl.value + "::" + ctrl.name  );
						$(ctrl).parent().find("p").text(ctrl.value);
					}
					if(etype=="label" && ctrl.value.length>0)
					{
						var onext = ctrl.nextElementSibling||ctrl.nextSibling;						
						onext.innerHTML=ctrl.value;
					}
					if(etype=="html" && ctrl.value.length>0)
					{
						KE.html(ctrl.id, ctrl.value);
						//alert(etype + "::" + ctrl.value + "::" + ctrl.id);
					}
					//alert(etype + "::" + ctrl.value);
					if(etype=="file" && ctrl.value.length>0)
					{
						var frame=getobj("frm" + ctrl.id );
						if(frame)
						{
							var src=frame.getAttribute("src");
							if(src.toLowerCase().indexOf("act=")==-1)
							{
								src+="&act=finsh";
							}
							src+="&file=" + ctrl.value;
							//alert(src);
							//alert(ctrl.id + "::" + data[e]);
							frame.src=src;
						}
					}
				}
				else
				{
					var type=Attribute(ctrl[0],"type").toLowerCase();
					var _tmp="," + data[e].decode() + ",";
					for(var i=0;i<ctrl.length;i++)
					{
						if(_tmp.indexOf("," + ctrl[i].value + ",")>-1)
						{
							ctrl[i].checked=true;
						}
					}
				}
			}
		}
	});
	
	eDataTable_Init();
};
//OK
function form_delete(obj,ModelID,delText)
{
	if(!delText){delText="删除";}
	var Prefix="M" + ModelID + "_";
	Prefix="";
	if(!confirm("确认要" + delText + "吗？")){return;}
	
	var tr=getParent(obj,"tr");
	if(tr.getAttribute("eRowID")==null)
	{
		tr=getParent(tr.parentNode,"tr");
	}
	//alert(tr.getAttribute("eRowID"));
	//return;
	var tbody=getParent(tr,"tbody");
	var trs=tbody.getElementsByTagName("tr");
	//var index=0;
	//for(i=0;i<trs.length;i++){if(trs[i]== tr){index= i;}}
	var index=tr.Index();
	
	var input=getobj("eformdata_" + ModelID);
	
	var model=input.value.toJson();
	//model.Convert=true;

	
	var _model=model.get("eformdata_" + ModelID);
	_model=_model[index];
	

	if(_model[Prefix + "ID"].length==0)
	{
		_model=model.get("eformdata_" + ModelID)
		_model.remove(index);
		tbody.removeChild(tr);
	}
	else
	{
		_model[Prefix + "Delete"]="true";		
	
		tr.style.display="none";
	}
	//更新顺序号
	var otable=getobj("eformlist_" + ModelID);	
	var otfoot=otable.getElementsByTagName("tfoot")[0];
	var otr=otfoot.getElementsByTagName("tr")[0].cloneNode(true);
	var otds=otr.getElementsByTagName("td");
	var row_index=-1;
	for(var i=0;i<otds.length;i++)
	{
		if(otds[i].innerHTML.toLowerCase().indexOf("row:index")>-1)
		{
			row_index=i;
			break;
		}
	}
	if(row_index>-1)
	{
		$(tbody).find("tr:visible").each(function(i,elem){
			$(this).find("td:eq(" + row_index + ")").html(i + 1); 
		});
	}
		
	//var count=getobj("count_" + ModelID);
	var count;
	if(form_area)
	{
		count=form_area.find("#count_" + ModelID);
		count=count.length>0 ? count[0] : count=getobj("count_" + ModelID);
	}
	else
	{
		count=getobj("count_" + ModelID);
	}
	if(count)
	{
		
		count.value= $(tbody).find("tr:visible").length;// tbody.children.length;
	}
	input.value=model.toJson();	

	//回调函数-删除
	if(typeof(submodel_onChange)=="function")
	{
		var list_trs=$("#eformlist_" + ModelID + " tbody tr");
		submodel_onChange(ModelID,list_trs,tbody);
	}
};
//OK
function form_save(ModelID)
{
	
	var frm= document.forms["form_" + ModelID];
	if(!frm){alert("表单form_" + ModelID + "不存在!");return false;}	
	var Prefix="M" + ModelID + "_";
	Prefix="";
	var _back=eCheckform(frm);	
	if(!_back){return false;}
	var input=getobj("eformdata_" + ModelID);
	//alert(input.value);
	var model=input.value.toJson();	
	//model.Convert=true;
	
	//alert(model.toJson());
	//return;
	var _data=model.get("eformdata_" + ModelID);

	var index=parseInt(frm[Prefix + "Index"].value);
	var table=getobj("eformlist_" + ModelID);
	var tbody=table.getElementsByTagName("tbody")[0];

	var obj= formToJson(frm);
	//alert(new eJson(obj).toJson());
	
	var tfoot=table.getElementsByTagName("tfoot")[0];
	var otr=tfoot.getElementsByTagName("tr")[0].cloneNode(true);
	var otds=otr.getElementsByTagName("td");
	if(index>-1)//替换
	{
		_data[index]=obj;
		
		//var tr=tbody.getElementsByTagName("tr")[index];
		var tr=tbody.children[index];
		//tr,td 不可以使用getElementsByName  getElementById 所以要从TD 去读JSON数据，而不是从Json数据到TD
		//alert(tr.outerHTML);
		
		
		 $(tr).find("[name]").each(function(i,elem){
			var name=elem.getAttribute("name");
			if(name)
			{
				var _opar= $(otr).find("[name='" + name + "']").get(0);
				name=name.replace("td_","");
				if(obj[name+"_Text"])
				{
					elem.innerHTML=obj[name+"_Text"].decode();				
				}
				else
				{
					if(obj[name])
					{
						
						if(_opar.innerHTML.toLowerCase().indexOf("data:")==-1)
						{
							elem.innerHTML=obj[name].decode();
						}
						else
						{
							elem.innerHTML=_opar.innerHTML.replace(/{data:.*?}/gi,obj[name].decode());
						}
						
					}
					else
					{
						if(name.length>0 && _opar.innerHTML.toLowerCase().indexOf("data:")> -1){elem.innerHTML="";}
					}
				}
			}
	     });
		

		/*
		var tds=tr.getElementsByTagName("td");
		for(var i=0;i<tds.length;i++)
		{
			var name=tds[i].getAttribute("name").replace("td_","");//正
			if(name)
			{
				if(obj[name+"_Text"]){tds[i].innerHTML=obj[name+"_Text"].decode();continue;}
				
				if(obj[name])
				{
					if(otds[i].innerHTML.toLowerCase().indexOf("data:")==-1)
					{
						tds[i].innerHTML=obj[name].decode();
					}
					else
					{
						tds[i].innerHTML=otds[i].innerHTML.replace(/{data:.*?}/gi,obj[name].decode());
					}
				}
				else
				{
					tds[i].innerHTML="";
				}
			}
		}
		*/
	}
	else //添加
	{
		_data.append(obj);

		$(otr).find("[name]").each(function(i,elem){
			var name=elem.getAttribute("name");
			if(name)
			{
				name=name.replace("td_","");
				if(obj[name+"_Text"])
				{
					elem.innerHTML=obj[name+"_Text"].decode();				
				}
				else
				{
					if(obj[name])
					{
						if(elem.innerHTML.toLowerCase().indexOf("data:")==-1)
						{
							elem.innerHTML=obj[name].decode();
						}
						else
						{
							elem.innerHTML=elem.innerHTML.replace(/{data:.*?}/gi,obj[name].decode());
						}
						
					}
					else
					{
						//elem.innerHTML="";
						//alert($(tbody).find("tr").length);
						//更新顺序号
						elem.innerHTML=elem.innerHTML.replace(/{row:index}/gi,$(tbody).children("tr").length + 1);
					}
				}
			}
		});		
		/*
		for(var i=0;i<otds.length;i++)
		{
			var name=otds[i].getAttribute("name").replace("td_","");
			if(name)
			{
				if(obj[name+"_Text"]){otds[i].innerHTML=obj[name+"_Text"].decode();continue;}
				if(obj[name])
				{
					
					if(otds[i].innerHTML.toLowerCase().indexOf("data:")==-1)
					{
						
						
						otds[i].innerHTML=  obj[name].decode();
					}
					else
					{
						otds[i].innerHTML=otds[i].innerHTML.replace(/{data:.*?}/gi,obj[name].decode());
					}
				}
				else
				{
					otds[i].innerHTML="";
				}
			}
		}
		*/
		tbody.appendChild(otr);
		//alert(table.parent);
		if(table.parent){Table_Init_Tbody(table.parent);}
		
	}
	//alert(model.toJson());
	input.value=model.toJson();
	//form_cancel(ModelID);
	//var count=getobj("count_" + ModelID);
	var count;
	if(form_area)
	{
		count=form_area.find("#count_" + ModelID);
		count=count.length>0 ? count[0] : count=getobj("count_" + ModelID);
	}
	else
	{
		count=getobj("count_" + ModelID);
	}
	if(count)
	{
		count.value=$(tbody).find("tr:visible").length;// tbody.children.length;
	}
	//回调函数-添加修改
	if(typeof(submodel_onChange)=="function")
	{
		var list_trs=$("#eformlist_" + ModelID + " tbody tr");
		submodel_onChange(ModelID,list_trs,tbody);
	}


	/*
	
	setTimeout(function(){
	eDataTable_Init();
	if(table.parent){Table_Init_Tbody(table.parent);}
	//alert(table.id);
	},500);
	
	if(!table.parent)
	{
		eDataTable_Init();
	}
	else
	{
		Table_Init_Tbody(table.parent);
	}
	*/
	return true;
};


//OK

/*
var query="";
	if(typeof(OpenFillSelectDlg_before)=="function")
	{
		var _back=OpenFillSelectDlg_before(modelID);
		if(typeof(_back)=="object")
		{
			//if(!_back.result){return;}
			query=_back.query;
			if(query.length>0)
			{
				if(query.indexOf("&")!=0){query="&" + query;}			
			}
		}
	}
	var url="../Plugins/FillSelectData.aspx?modelid=" + modelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "");
	if(query.length>0){url+=query;}
	*/



function getAddHTML(ModelID,_url)
{


	var html="";	
	
	//eval("var modelhtml=window.ModelHTML_" + ModelID + ";");
	var modelhtml=eval("window.ModelHTML_" + ModelID.replace(/-/gi,"") );
	
	if(modelhtml)
	{
		html=modelhtml;
		//document.title="get";
	}
	else
	{
		//var url="?modelid=" + ModelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "")  + "&act=addsub";
		
		var url="?modelid=" + ModelID + "&act=addsub";
		if(_url){url=_url;}
		
	
		if(typeof(getAddHTML_before)=="function")
		{
			
			var _back=getAddHTML_before(ModelID);
			if(typeof(_back)=="object")
			{
				//if(!_back.result){return;}
				if(_back.query.length>0)
				{
					//url+= url.indexOf("?") > -1 ? "&" + _back.query : "?"  + _back.query ;
					var query=_back.query.replace("?","");
					var arr=query.split("&");
					for(var x=0;x<arr.length;x++)
					{
						var arr2=arr[x].split("=");
						if(arr2.length==2)
						{
							url=url.addquerystring(arr2[0],arr2[1]);
						}
					}
				}
			}
		}
		if(url.indexOf("pid=")==-1)
		{
			var id=document.location.href.getquerystring("id");
			if(id.length>0)
			{
				url+= url.indexOf("?") > -1 ? "&pid=" + id : "?pid="  + id ;
			}
		}
		
		var debug=document.location.href.getquerystring("debug");
		if(debug.length>0) url+= "&debug=" + debug; 
		url+= "&t=" + now();
		html=PostURL(url);
		eval('window.ModelHTML_'+ ModelID.replace(/-/gi,"") +'=html;');
		//document.title="set";
	}
	return html;
};

function form_init(ModelID)
{

	var frm= document.forms["form_" + ModelID];
	if(!frm){alert("表单form_" + ModelID + "不存在!");return false;}
	
	var executenames="";
	var elements=frm.elements;
	
	for(var i=0; i < elements.length; i++)
	{
		if(executenames.indexOf(elements[i].name.toLowerCase())>-1){continue;}
		if(elements[i].getAttribute("Exclude")!=null || elements[i].getAttribute("exclude")!=null){continue;}
		if(elements[i].tagName.toLowerCase()=="fieldset"){continue;}
		if(elements[i].name.toLowerCase()=="index"){continue;}
		if(elements[i].name.toLowerCase().indexOf("_index") > -1 ){continue;}
		if(elements[i].name.toLowerCase()=="page"){continue;}
		
		//var fieldname = elements[i].getAttribute("fieldname");
		
		var defaultvalue = elements[i].getAttribute("defaultvalue");
		
		if(defaultvalue==null){defaultvalue="";}
		if(elements[i].name.indexOf("eformdata_")>-1)
		{
			
			var table=getobj(elements[i].name.replace("eformdata_","eformlist_"));
			if(table)
			{
				if(table.getAttribute("reinit")=="false"){continue;}
				var tbody=table.getElementsByTagName("tbody")[0];			
				var trs=tbody.getElementsByTagName("tr");					
				for(var j=trs.length;j > 0;j--)
				{
					trs[0].parentNode.removeChild(trs[0]);
				}
			}
			elements[i].value='{"' + elements[i].name + '":[]}';
		}
		else
		{
			var etype = elements[i].getAttribute("etype");
			if(etype==null){etype="";}
			//alert(etype + defaultvalue);
			if(defaultvalue.length>0 && etype != "checkbox" && etype!="radio")
			{
				elements[i].value = defaultvalue;
			}
			else
			{
				if(etype != "checkbox" && etype!="radio")
				{
					elements[i].value = "";
				}
			}
			if(etype=="autoselect" && elements[i].name.indexOf("all")==-1)
			{
				
				var tmp;
				for(var j=2;j<10;j++)
				{
					tmp=getobj(elements[i].name + "_" + j);
					

					if(!tmp){break;}
					tmp.parentNode.removeChild(tmp);
				}
				tmp=getobj(elements[i].name + "_1");
				tmp.value="";
			}
			if(etype=="file")
			{
				var frame=getobj("frm" + elements[i].name);
				var url=frame.getAttribute("src");
				url=url.removequerystring("act");
				url=url.removequerystring("file");
				
				frame.src=url;
			}
			if(etype=="html"){KE.html(elements[i].name,defaultvalue);}
			if(etype=="checkbox" || etype=="radio")
			{
				executenames+="," + elements[i].name.toLowerCase() + ",";
				var chks=document.getElementsByName(elements[i].name);
				for(var j=0; j < chks.length; j++)
				{
					chks[j].checked=(defaultvalue.length > 0 && defaultvalue.indexOf(chks[j].value) > -1 ? true : false);
				}

			}
			
		}
	}
};
//OK
function submitform(frm)
{	
	if(typeof(frm)=="string"){frm= document.forms[frm];}
	if(!frm){return;}
	if(frm.onsubmit()!=false)
	{
		frm.submit();
		var loading= document.createElement("div");
		loading.className="eform_loading";
		document.body.appendChild(loading);
	}
};
//删除HTML标签
function removeHTMLTag(str){
    return str.replace(/<\/?.+?\/?>/g,'');
}
function packform(ModelID,ajax)
{
	if(Attribute(frmaddoredit,"finsh")=="true"){return;}
	
	var frm= document.forms["form_" + ModelID];
	if(!frm){alert("表单form_" + ModelID + "不存在!");return;}

	var _back=eCheckform(frm);
	if(!_back){return;}	

//return;
	//alert($(frm).find(".excelTable").length);
	//return;
	//clearPack($(frm));//清除合并标记

/*
	$(frm).find(".excelTable").each(function(i,el){
		if($(this).attr("exclude")=="undefined" || $(this).attr("exclude")!="true")
		{
			form_area=$(this).parent();
			excel_pack($(this).attr("id").replace("eformlist_",""));
		}
	});	


	//从没有下拉的列表往上汇总
	var ctrls = new Array();
	$(frm).find(".divsubList").each(function(i,el){	
		$(this).attr("pack","false");
		if($(this).find(".divsubList").length==0)
		{
			ctrls.push($(this));
		}
	});
	if(ctrls.length>0){eachItems(ctrls);}
	*/


	

	//return false;
	//alert($(frm).find(".excelTable").length);

	var frmobj= formToJson(frm);	
	//alert(frmobj.toJson());
	//return;
	var obj=new eJson2([]);
	obj.append(frmobj);
	//alert(obj);
	//alert(ModelID);
	//var xx=$(frm).serialize()
	//alert(xx);
	//return;
	
	//var str='{"eformdata_' + ModelID + '":[]}';
	//var model=str.toJson();	
	//model["eformdata_"+ ModelID]=obj;

	//alert(obj.toJson());
	//return;
	

	
	//var model=new eJson();
	//model.Convert=true;
	//model.append("ModelID",ModelID);
	//model.append("eformdata_" + ModelID,obj);	
	//alert("xx:" + model.toJson());
	
	
	var model=new eJson2();
	model.append("ModelID",ModelID);	
	model.append("eformdata_" + ModelID,obj);
	var input=getobj("eformdata_" + ModelID);	
	
	//alert(model.toJson());
	//return;
	input.value= model.toJson();
	
	//$("#eformdata_result").val(model.toJson());
	//alert(model.toJson());
	//alert(obj.toJson());
	//return;
	//alert(ajax);
	//return;
	if(ajax)
	{
	
		//alert("ajax" + $("#frmaddoredit").serialize());
		//if(!frmaddoredit["ajax"]){var input= document.createElement("input");input.type="hidden";input.name="ajax";input.value="true";frmaddoredit.appendChild(input);}
		$.ajax({
			type: 'post',
			async: false,
			url: $("#frmaddoredit").attr("action"),			
			data: "ajax=true&" + $("#frmaddoredit").serialize(),
			dataType: "json",
			success: function(data)
			{

				//layer.alert(data,{title:"提示" ,area: ['800px', '600px']});
				//alert(data);
				var json=new eJson2(data);
				//alert(typeof(parent.postback) + "::" + _json.toJson());
				//return;
				if(typeof(parent.postback)=="function")
				{
					parent.postback(data);
					return;
				}


				//data=eJson(data);
				if(parseBool(data.success))
				{
					//var json=eJson(data);
					//json.Convert=true;
					if(frmaddoredit["id"] && frmaddoredit["id"].value){frmaddoredit["id"].value = json["id"];}
					if(frmaddoredit["ID"] && frmaddoredit["ID"].value){frmaddoredit["ID"].value = json["id"];}
					if(frm["id"] && frm["id"].value){frm["id"].value = json["id"];}
					if(frm["ID"] && frm["ID"].value){frm["ID"].value = json["id"];}
					//layer.alert( json["id"] + "::" +  json.toJson(),{title:"提示" ,area: ['800px', '600px']});
					//alert(json.toJson());
				
					//var data=json.get("data").get(0);
					//data.Convert=true;		
					
					//alert( json["id"] + "::" +json.id );
					
					//form_init(ModelID);
					//input.value=data.toJson();
					//form_load(ModelID);
					
					//layer.msg("保存成功!");
					//if(frm["id"]){frm["id"].value=json.id;}
					//if(frm["ID"]){frm["ID"].value=json.id;}
					
					
					if(top!=self)//Frame打开
					{	
							if(parent.arrLayerIndex.length>0)
							{
								parent.layer.msg(data.message);
								//$(parent.document).find(".excelTable tbody tr:visible"); //layui-layer1
								var index = parent.layer.getFrameIndex(window.name);
								$(parent.document).find("#layui-layer-shade" + index).hide();								
								$(parent.document).find("#layui-layer" + index).hide();
								//alert(index);
								var _count=parent.arrLayerIndex.length;
								setTimeout(function(){
									parent.layer.close(parent.arrLayerIndex.pop());
									//parent.document.location.assign(parent.document.location.href);
									if(_count==1)
									{
										var curtab = $(parent.document).find(".eFrameTab dt a.cur");
 										var doc= $(parent.document).find(".eFrameTab dd iframe:eq(" + curtab.index() + ")").get(0).contentWindow;
										doc.Search();
									}
									else
									{
										var win=$(parent.document).find("#layui-layer-iframe" + parent.arrLayerIndex[parent.arrLayerIndex.length-1]);
										if(win)
										{
											win.get(0).contentWindow.Search();
										}
									}
 									//doc.location.assign(doc.location.href);
									//if(parent.arrLayerIndex.length==0)parent.Search();
								},1000);
								
							}
					}
					else
					{
						
					}
					/*
					layer.msg(data.message, {
					time: 0 //20s后自动关闭
					,shade: 0.2 //透明度
					,shadeClose: false //点击遮罩关闭层
					
					,btn: ["添加新记录","继续修改","返回"]
					,yes:function(index,layero)
					{
						
						//layer.msg("添加" + ModelID);
						input.value="";
						form_init(ModelID);

						if(frm["id"]){frm["id"].value="";}
						if(frm["ID"]){frm["ID"].value="";}
						layer.close(index);
					}
				    ,btn2:function(index,layero)
					{
						if(frm["id"]){frm["id"].value=json.id;}
						if(frm["ID"]){frm["ID"].value=json.id;}
						//layer.msg("修改");
					}
					,btn3:function(index,layero)
					{
						//layer.msg("返回" + frmaddoredit["fromurl"].value);
						//document.location.assign(frmaddoredit["fromurl"].value);
						if(top!=self)//Frame打开
						{	
							if(parent.arrLayerIndex.length>0)
							{

								parent.layer.close(parent.arrLayerIndex.pop());
								if(parent.arrLayerIndex.length==0)parent.Search();
							}
						}						
					}
				  	});
					*/
				}
				else
				{
					
					//alert("失败!");
				}

				
			}
		});
	}
	else
	{
		//var btn=getEventObject();
		
		frmaddoredit.setAttribute("finsh","true");
		frmaddoredit.submit();
		return;
		var loading= document.createElement("div");
		loading.className="eform_loading";
		document.body.appendChild(loading);
	}
	return;
};
function removeAddNew(obj,ModelID)
{	
	var dl=$(obj).parents("dl:first");
	var list=dl.parent();//div
	var inputid=dl.find("input[postname='ID']");
	var id=inputid.val();
	if(id.length==0)
	{
		dl.remove();
	}
	else
	{
		var _back=confirm('确认要删除吗？');
		if(!_back){return;}	
		dl.find("input[postname='Delete']").val("true");
		dl.find("input[id*='count_']").remove();
		dl.hide();
		//addPack(dl);
	}
	ItemToJson(list);	
};

function addNew(obj,ModelID)
{
	form_area=$(obj).parents("dd:first");
	var html=getAddHTMLN(ModelID);	
	//$(obj).before(html);	
	var list=$(obj).parent().find("#eformlist_" + ModelID + ":first");
	list.append(html);
	

	
	//alert(list.find(">dl").length + "::" + list.find(">dl:last").index());
	var _row=list.find(">dl").length;	
	list.find(">dl:last").find("input[type='radio']").each(function(i,el)
	{
		//alert(el.value + "::" + el.name);
		var _name=$(this).attr("name");
		if(_name.indexOf("{row}")>-1 )
		{
			_name=_name.replace("{row}","row_" + _row + "_");
			$(this).attr("name",_name);
		}
	});
	
	
	

	ItemToJson(list);
	//alert(html);
	/*
	var url=document.location.href;
	url=url.removequerystring("id");
	url=url.removequerystring("act");
	url=url.addquerystring("ModelID",ModelID);
	url=url.addquerystring("act","addsub");	
	if(typeof(getAddHTML_before)=="function")
	{			
		var _back=getAddHTML_before(ModelID);
		if(typeof(_back)=="object")
		{
			//if(!_back.result){return;}
			if(_back.query.length>0)
			{
				url+= url.indexOf("?") > -1 ? "&" + _back.query : "?"  + _back.query ;
			}
		}
	}
	if(url.indexOf("pid=")==-1)
	{
		var id=document.location.href.getquerystring("id");
		if(id.length>0)
		{
			url+= url.indexOf("?") > -1 ? "&pid=" + id : "?pid="  + id ;
		}
	}
		
	var debug=document.location.href.getquerystring("debug");
	if(debug.length>0) url+= "&debug=" + debug; 
	url+= "&t=" + now();
	*/
	//alert(ModelID + "::" + url);
};
function eachItems(arr)
{
	var ctrls = new Array();
	//for(p in arr)
	for(var i=0;i<arr.length;i++)
	{
		var div=arr[i];//arr[p];
		eachItem(div);
		var pdiv=div.parents(".divsubList:first");
		if(pdiv.length>0){ctrls.push(pdiv);}
	}
	if(ctrls.length>0){eachItems(ctrls);}
};
function eachItem(div)//div
{
	//alert(div.html());
	var pack=div.attr("pack");
	if(pack=="true"){return;}
	form_area=div;
	
	ItemToJson(div);
	div.attr("pack","true");
	//alert(div.parents(".divsubList:first").length);
	//if(div.parents(".divsubList:first").length>0)
	//{
		//var pdiv=div.parents(".divsubList:first");
		//eachItem(pdiv);
		//alert(pdiv.length);
		//alert(pdiv.attr("id") + "::" + pdiv.find("input:not([pack])").length + "::" +  pdiv.find("input").not("[pack]").length);
	//}
};

function ItemToJson(div) //div
{
	var _modelid=div.attr("id").replace("eformlist_","");
	var txtid=div.attr("id").replace("eformlist_","eformdata_");
	var _data="[]".toJson();	
	//_data.Convert=true;
	//alert(div.find(">dl>dd").length + "X");
	//div.find(">dl>dd").each(function(j,elem){
	if(div.parent().find("#count_" + _modelid).length>0)
	{
		div.parent().find("#count_" + _modelid).val(div.children("dl").children("dd").length);
	}
	div.children("dl").children("dd").each(function(j,elem){
		var _item= nodeToJson(elem);	
		if(_item.toJson().length>2)
		{
			_data.append(_item);
		}
	});
	//alert(_data.toJson());
	
	var _model=new eJson2();
	
	//_model[txtid]=_data;
	_model.append(txtid,_data);
	//$("#" + txtid).val(_model.toJson());
	//alert(_model.toJson());
	div.prevAll("#" + txtid).val(_model.toJson() );
};

//OK
function clearPack(node)
{
	var inputs=$(node).find("input[pack]");
	for(var i=0;i < inputs.length;i++)
 	{
		 $(inputs[i]).removeAttr("pack");
	}
	var selects=$(node).find("select[pack]");
	for(var i=0;i < selects.length;i++)
 	{
		 $(selects[i]).removeAttr("pack");
	}
	var textareas=$(node).find("textarea[pack]");
	for(var i=0;i < textareas.length;i++)
 	{
		 $(textareas[i]).removeAttr("pack");
	}
};
function addPack(node)
{
	var inputs=$(node).find("input");
	for(var i=0;i < inputs.length;i++)
 	{
		 $(inputs[i]).attr("pack","true");
	}
	var selects=$(node).find("select");
	for(var i=0;i < selects.length;i++)
 	{
		 $(selects[i]).attr("pack","true");
	}
	var textareas=$(node).find("textarea");
	for(var i=0;i < textareas.length;i++)
 	{
		 $(textareas[i]).attr("pack","true");
	}
};
function nodeToJson(node)
{
	var el=$(node)[0];	
	if(el.tagName!="DD"){clearPack(node);} //不能清除整个子模块内容
	var tfoot=$(node).find("tfoot");
	if(tfoot.length>0){addPack(tfoot);}
	var json=new eJson2();
	

	
	//var inputs=node.getElementsByTagName("input");
	var inputs=$(node).find("input:not([pack])");
	//alert(inputs.length);
	//alert(inputs.length);
 	for(var i=0;i < inputs.length;i++)
 	{
		var type= inputs[i].getAttribute("type").toString().toLowerCase();
		//if(inputs[i].getAttribute("Exclude")!=null || inputs[i].getAttribute("exclude")!=null){continue;}
		if(type == "submit" || type == "button" || type == "reset"){continue;}
		var postname=inputs[i].name;
		//alert(postname);
		if(inputs[i].getAttribute("postname")){postname=inputs[i].getAttribute("postname");}
		if(postname.length==0){continue;}	
		if(postname.toLowerCase().indexOf("eformdata_")==-1)
		{
			
		 	$(inputs[i]).attr("pack","true");
			//inputs[i].style.borderColor="#ff0000";
		}
		//if(postname.toLowerCase().indexOf("eformdata_")==-1){ $(inputs[i]).attr("pack","true");}
		//json["name"]=postname;
		
		var value=  postname.toLowerCase().indexOf("eformdata_") > -1 ? inputs[i].value.trim() : inputs[i].value.trim().encode();
		if((type == "radio" || type=="checkbox") && inputs[i].checked==false){value="";}
		
		if(postname.toLowerCase().indexOf("eformdata_")>-1) //子模块对象 
		{

			var _json=value.toJson();
			_json=_json.get(postname);
			
			//_json.Convert=true;
			//json[postname]=_json;
			json.append(_json);
			
		}
		else
		{
			if(!json[postname])
			{
				json[postname] = value;
			}
			else
			{
				if(value.length>0){json[postname] += "," + value;}
			}
		}		
		//inputs[i].name="";
 	}

 	//var selects=node.getElementsByTagName("select");
	var selects=$(node).find("select:not([pack])");
	for(var i=0;i < selects.length;i++)
	{
		$(selects[i]).attr("pack","true");
		var postname=selects[i].name;
		if(selects[i].getAttribute("postname")){postname=selects[i].getAttribute("postname");}
		if(postname.length==0){continue;}
		var value=selects[i].value.trim().encode();
		json[postname] = value;
		//selects[i].name="";
	}
	//var textareas=node.getElementsByTagName("textarea");
	var textareas=$(node).find("textarea:not([pack])");
	for(var i=0;i < textareas.length;i++)
	{
		//$(textareas[i]).attr("pack","true");
		var postname=textareas[i].name;
		if(textareas[i].getAttribute("postname")){postname=textareas[i].getAttribute("postname");}
		if(postname.length==0){continue;}
		if(postname.toLowerCase().indexOf("eformdata_")==-1)
		{
			$(textareas[i]).attr("pack","true");
			//textareas[i].style.borderColor="#ff0000";			
		}
		//json["name"]=postname;
		//if(postname.toLowerCase().indexOf("eformdata_")==-1){ $(textareas[i]).attr("pack","true");}
		
		var value=  postname.toLowerCase().indexOf("eformdata_") > -1 ?  textareas[i].value.trim() : textareas[i].value.trim().encode();
		if(postname.toLowerCase().indexOf("eformdata_")>-1) //子模块对象 
		{
			var _json=value.toJson();
			_json=_json.get(postname);
			//_json.Convert=true;
			//json[postname]=_json;
			json.append(_json);
		}
		else
		{
			json[postname] = value;
		}
		//textareas[i].name="";
	}
	$(node).find("[name^='eformdata_']").each(function(j,elem){
			var _json=$(this).val().toJson();
			_json=_json.get($(this).attr("name"));
			json.append($(this).attr("name"),_json)										
			//alert($(this).val());	   
		//excel_pack($(this).attr("id").replace("eformlist_",""));
	});
	addPack(node);
	return json;
};
//OK
function TableToJson(ModelID)
{
	var model=new eJson2([]);
	//model.Convert=true;
	//var table=getobj("eformlist_" + ModelID);
	var table;
	if(form_area)
	{
		table=form_area.find("#eformlist_" + ModelID);
		table=table.length>0 ? table[0] : getobj("eformlist_" + ModelID);
	}
	else
	{
		table=getobj("eformlist_" + ModelID);
	}
	
	
	var tbody=table.getElementsByTagName("tbody")[0];
	var trs=tbody.getElementsByTagName("tr");
	
	for(var j=0;j < trs.length;j++)
 	{
  		model.append("eformdata_" + ModelID,nodeToJson(trs[j]));
	}
	//var input=getobj("eformdata_" + ModelID);
	var input;
	if(form_area)
	{
		input=form_area.find("#eformdata_" + ModelID);		
		input=input.length>0 ? input[0] : getobj("eformdata_" + ModelID);
	}
	else
	{
		input=getobj("eformdata_" + ModelID);
	}
	
	input.value=model.toJson();
};
function formToJson(frm)//eJson2
{
	if(typeof(frm)=="string"){frm= document.forms[frm];}
	var elements=frm.elements;
	//alert(elements.length);
	//var json=new Object();
	clearPack($(frm));
	$(frm).find(".excelTable").each(function(i,el){
		if($(this).attr("exclude")=="undefined" || $(this).attr("exclude")!="true")
		{
			form_area=$(this).parent();
			excel_pack($(this).attr("id").replace("eformlist_",""));
		}
	});	



	
	var ctrls = new Array();
	$(frm).find(".divsubList").each(function(i,el){	
		$(this).attr("pack","false");
		if($(this).find(".divsubList").length==0)
		{
			ctrls.push($(this));
		}
	});
	
	if(ctrls.length>0){eachItems(ctrls);}
	
	


	var json=new eJson2();
	for(var i=0; i < elements.length; i++)
	{
		
		var pack=$(elements[i]).attr("pack");
		if(pack=="true"){continue;}
		//alert(elements[i].name + "::" + pack);
		
		if(elements[i].getAttribute("Exclude")!=null || elements[i].getAttribute("exclude")!=null){continue;}		
		if(elements[i].tagName.toLowerCase()=="fieldset"){continue;}
		if(elements[i].name.toLowerCase()=="index"){continue;}
		if(elements[i].name.toLowerCase().indexOf("_index") > -1 ){continue;}
		if(elements[i].name.toLowerCase()=="page"){continue;}
		if(elements[i].name.toLowerCase().indexOf("_result") > -1 ){continue;}
		if(elements[i].name.length==0){continue;}
		//$(document.body).append(elements[i].name + "<br>");
		
		//alert(elements[i].name);
		//continue;
		var type= "";
		if(elements[i].getAttribute("type")){type=elements[i].getAttribute("type").toString().toLowerCase();}
		
		if(type.length==0)
		{
			if(elements[i].tagName.toLowerCase()!="select" && elements[i].tagName.toLowerCase()!="textarea")
			{
				continue;
			}
		}		
		if(type == "submit" || type == "button" || type == "reset"){continue;}
		if((type == "radio" || type=="checkbox") && elements[i].checked==false){continue;}
	
		var value=elements[i].value;
		if(elements[i].tagName.toLowerCase()=="select" &&  elements[i].getAttribute("multiple")!=null)
		{

			var _tmp="";
			for(var j=0;j< elements[i].options.length;j++)
			{
				if( elements[i].options[j].selected)
				{
					if(_tmp.length>0){_tmp+=",";}
					_tmp+=elements[i].options[j].value;
				}
			}
			value=_tmp;
		}		
		
		if(type=="text" ||  elements[i].tagName.toLowerCase()=="textarea")
		{
			//if(elements[i].name.toLowerCase().indexOf("eformdata_") == -1) value = value.encode64();
		}

		if(elements[i].name.toLowerCase().indexOf("eformdata_")>-1) //子模块对象 
		{
			//alert("XX" + elements[i].name + "::" + value);
			var _json=value.toJson();
			//alert("a:" + _json.tostring());
			_json=_json.get(elements[i].name);
			
			//_json.Convert=true;
			//alert("B:" + _json.toJson());
			json.append(elements[i].name,_json);
			json[elements[i].name]=_json;
			//alert(_json.tostring());
			//alert();
			//json.append(elements[i].name,_json);
		}
		else
		{
			//alert(value + "::" + value.trim().encode());
			value=value.trim().encode();
			
			if(!json[elements[i].name])
			{
				//json[elements[i].name] = value;
				json.append(elements[i].name,value);
			}
			else
			{
				//json.append(elements[i].name,text + "," + value);
				json[elements[i].name] += "," + value;
			}
			//if(elements[i].getAttribute("etype")=="singleuser" && elements[i].name.toLowerCase().indexOf("_text")>-1 )
			//{
				//json[elements[i].name.replace("_t","_T")] = elements[i].value.encode();
			//}
			if(elements[i].getAttribute("etype")=="autoselect" && type=="hidden" && elements[i].name.toLowerCase().indexOf("_all")==-1 )
			{
				var txt="";
				for(var x=1;x<100;x++)
				{
					var tmp=getobj(elements[i].name + "_" + x);
					if(!tmp || tmp.value.length==0){break;}
					if(txt.length>0){txt+=",";}
					txt+=tmp.options[tmp.selectedIndex].text;					
				}
				json[elements[i].name + "_Text"] = removeHTMLTag(txt).encode();
			}
			if(elements[i].tagName.toLowerCase()=="select" && elements[i].selectedIndex > -1)
			{
				if(elements[i].getAttribute("multiple")==null)
				{
					json[elements[i].name + "_Text"] = removeHTMLTag(elements[i].options[elements[i].selectedIndex].text.replace("请选择","")).encode();
				}
				else
				{
					var _tmp="";
					for(var j=0;j< elements[i].options.length;j++)
					{
						if( elements[i].options[j].selected)
						{
							if(elements[i].options[j].value.length>0)
							{
								if(_tmp.length>0){_tmp+=",";}
								_tmp+=removeHTMLTag(elements[i].options[j].text).encode();
							}
						}
					}
					json[elements[i].name + "_Text"] =_tmp;
				}
			}
			if(type == "radio" || type=="checkbox")
			{
				if(elements[i].getAttribute("text"))
				{
					if(!json[elements[i].name + "_Text"])
					{
						
						json[elements[i].name + "_Text"] = removeHTMLTag(elements[i].getAttribute("text")).encode();
					}
					else
					{
						json[elements[i].name + "_Text"] += "," + removeHTMLTag(elements[i].getAttribute("text")).encode();
					}
				}
			}
			if(elements[i].name.toLowerCase().indexOf("_text")>-1 && (elements[i].getAttribute("etype")=="singleuser" || elements[i].getAttribute("etype")=="multipleuser"))
			{
				if(!json[elements[i].name.replace("_text","") + "_Text"])
				{
					json[elements[i].name.replace("_text","") + "_Text"] = removeHTMLTag(elements[i].value).encode();
				}
				else
				{
					json[elements[i].name.replace("_text","") + "_Text"] += "," + removeHTMLTag(elements[i].value).encode();
				}
			}
		}		
	}
	//addPack(frm);
	return json;
};
function JsonToTable(data,tableID)
{
	//alert(JSON.stringify(data));
	var table=getobj(tableID);	
	var tbody=table.getElementsByTagName("tbody")[0];
	var tfoot=table.getElementsByTagName("tfoot")[0];
	var clsname=table.className;
	data.foreach(function(e)
	{
		if(data[e]["Delete"]=="true") {return;}
		var tr=tfoot.getElementsByTagName("tr")[0].cloneNode(true);	
		if(data[e]["ID"] && tr.getAttribute("eRowID")!=null)
		{
			tr.setAttribute("eRowID",data[e]["ID"]);
		}
		//alert($(tr).find("[name]").length);		
		$(tr).find("[name]").each(function(i,elem){
			var name=elem.getAttribute("name");
			if(name)
			{
				var _opar= $(tr).find("[name='" + name + "']").get(0);
				name=name.replace("td_","");
				if(_opar.tagName=="TD")
				{
					if(data[e][name+"_Text"])
					{
						_opar.innerHTML=data[e][name+"_Text"].decode();
					}
					else
					{
						if(data[e][name])
						{							
							_opar.innerHTML=data[e][name].decode();
						}
					}
				}
				else
				{
					_opar.value=data[e][name];
				}
			}
		});
		/*
		var tds=tr.getElementsByTagName("td");
		for(var j=0;j<tds.length;j++)
		{
			var name=tds[j].getAttribute("name");
			if(name)
			{
				if(data[e][name+"_Text"])
				{
					tds[j].innerHTML=data[e][name+"_Text"].decode();
					continue;
				}
				if(data[e][name])
				{
					tds[j].innerHTML=data[e][name].decode();
				}
			}
		}
		*/
		tbody.appendChild(tr);
		//alert(tr.outerHTML);
	});	
	if(clsname=="excelTable")
	{
		
		var tr=$(table).find("thead td:contains('序号')");
		if(tr.length>0)
		{
			var _index=tr.index();
			$(tbody).find("tr:visible").each(function(i,elem){
				$(this).find("td:eq(" + _index + ")").html(i + 1); 
			});
		}
			//
		//clsname 	$("a:") //jQuery内容查找
		//alert(50);
	}
	//for(var i=0;i<otds.length;i++)
};
//OK
function form_cancel(ModelID)
{
	var form=getobj("form_" + ModelID);
	if(form){form["Index"].value="-1";}
	var frm=getobj("model_form_" + ModelID.replace(/-/gi,""));	
	if(frm){frm.parentNode.removeChild(frm);}
};
//$(document).ready(function() { }); 
//$("#id").unbind("click").click(function(e){  });
var quick_input;
var quick_show=false;
var quick_clip=null;
var quick_keys="";
function quick_search()
{
	quick_keys = quick_input.value;
	document.onkeydown=function(e)
	{
		e=window.event||e;
		var src=e.srcElement||e.target;
		var _show=$("#eSearchBox dd").is(':visible');
		if(e.keyCode==13 && _show)
		{
			//alert("##");
			return true; 
		}
		
		if(src.tagName != "BODY"){return true;}
		if(e.keyCode == 116 ){return true;}
		//document.title=e.keyCode;
		if(e.keyCode == 8 && quick_show )
		{
			if(quick_keys.length>0)
			{
				quick_keys=quick_keys.substring(0,quick_keys.length-1);
				quick_clip.innerHTML = quick_keys;
			}			
			if (e.stopPropagation){e.stopPropagation();}else{event.cancelBubble = true;}
			if (e.preventDefault){e.preventDefault();}else{e.cancelBubble = true;}
			return false;
		}
		if(e.keyCode<65 || e.keyCode>90){return false;}
		
		return true;
	};

	quick_clip = document.createElement("span");
	quick_clip.id = "quick_clip";
	quick_clip.className="quick_clip";
	quick_clip.style.display = "none";
	
	quick_clip.innerHTML = quick_keys;// 'ABC';
	document.body.appendChild(quick_clip);

	
	
	$("body").bind("keydown",function(e){  
		e=window.event||e;
		var src=e.srcElement||e.target;
		
		var _show=$("#eSearchBox dd").is(':visible');
		if(e.keyCode==13 && _show)
		{
			//alert(5);
			e.keyCode = 0;
			return true; 
		}
		/*
		if(e.keyCode==13 && _show)
		{
			goSearch(frmsearch);
			//goSearch(document.forms["frmsearch"]);
			return true;  
		}
		*/
		
		if(src.tagName != "BODY"){return true;}
		//document.title+=e.keyCode;// String.fromCharCode(e.keyCode);
		if(e.keyCode==27)//ESC
		{
			quick_keys="";
			quick_show=false;
			quick_clip.style.display = "none";
			quick_clip.innerHTML = quick_keys;
			return false;  
		}
		if(e.keyCode==13)//回车
		{
			//alert(66);
			if(quick_show)
			{
				
				quick_show=false;
				quick_clip.style.display = "none";
				if(quick_keys.length>0 || quick_keys.length == 0)
				{
					quick_input.value=quick_keys;
					var tb=getobj("eDataTable");
					var ajax=false;
					if(tb)
					{
						ajax = parseBool(tb.getAttribute("ajax"));
					}
					if(ajax)
					{
						Search(1);
					}
					else
					{
						goSearch(document.forms["frmsearch"]);
					}
				}
			}
			else
			{
				quick_show=true;
				quick_clip.style.display = "";
			}
			e.keyCode = 0;
			return false;  
		}
		//if(quick_show && e.keyCode>= 65&& e.keyCode<=90)
		if(quick_show && e.keyCode>= 65 )
		{
			
			quick_keys+=String.fromCharCode(e.keyCode);
			quick_clip.innerHTML = quick_keys;
		}
		
	});
};
//星级评分初始
function raty_init()
{
	 $('.raty').each(function(i,elem){ 
		
		var dataid=$(this).attr('data-id');
		var staroff = $(this).attr('data-staroff');	
		var starhalf = $(this).attr('data-starhalf');
		var staron = $(this).attr('data-staron');
		var _readonly = $(this).attr('data-readonly');
		var readonly=false;
		if(_readonly=="true"){readonly=true;}
		var _half = $(this).attr('data-half');
		var half=false;
		if(_half=="true"){half=true;}
		
		if(dataid)
		{
			$(this).raty({ 
				  width:'100%',
				  hints: ['','','','',''],
				  readOnly: readonly, 
				  targetType: 'number',
				  targetKeep: true,
				  half: half,
				  halfShow: half,
				  target    : '#' + dataid,
				  score: function() { return $(this).attr('data-score');},
				  number: function() {return $(this).attr('data-number'); },  
				  starOff : staroff,
				  starHalf  : starhalf,
				  starOn  : staron			  
			  });
		}
		else
		{
			$(this).raty({ 
				  width:'100%',
				  hints: ['','','','',''],
				  readOnly: readonly, 
				  targetType: 'number',
				  targetKeep: true,
				  half: half,
				  halfShow: half,
				  score: function() { return $(this).attr('data-score');},
				  number: function() {return $(this).attr('data-number'); },  
				  starOff : staroff,
				  starHalf  : starhalf,
				  starOn  : staron			  
			  });
		}
	});
	
};

function init()
{	
	//if(document.all)
	if(!window.addEventListener)
	{
		//display: flex;align-items: center; IE文字消失问题 https://blog.csdn.net/weixin_34247032/article/details/94585514
		//$(".eDataTable tbody td div").css("float","left");
	}
	$(document).find("input[onblur*='MakePinyin']").each(function(index, elem) {		
	$(this).trigger("blur");;
	});
	
	
	if(jQuery)
	{
		//$(document).find("a:contains('删')[onclick]").each(function(i,elem){
		$(document).find("a:contains('删')[onclick*='confirm']").each(function(i,elem){		
			
			$(this).attr("_href",$(this).attr("href"));
			$(this).attr("href","javascript:;");
			var title=$(this).attr("onclick");
			title=title.substring(title.indexOf("(")+1);
			title=title.substring(0,title.indexOf(")"));
			title=title.replace(/'/g,"").replace(/"/g,"");
			elem.onclick=function()
			{				
				//var aa=confirm('确认要删除吗？');
				var aa=confirm(title);
				if(aa){document.location.href=$(elem).attr("_href");}
			};
		});
		function buildParams( prefix, obj, traditional, add )
		{
			var name;
		
			if ( jQuery.isArray( obj ) ) {
		
				// Serialize array item.
				jQuery.each( obj, function( i, v ) {
					if ( traditional || rbracket.test( prefix ) ) {
		
						// Treat each array item as a scalar.
						add( prefix, v );
		
					} else {
		
						// Item is non-scalar (array or object), encode its numeric index.
						buildParams(
							prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
							v,
							traditional,
							add
						);
					}
				} );
		
			} else if ( !traditional && jQuery.type( obj ) === "object" ) {
		
				// Serialize object item.
				for(name in obj ) {
					if(typeof(obj[name])=="function"){continue;} 
					buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
				}
		
			} else {
		
				// Serialize scalar item.
				add( prefix, obj );
			}
		};
	
		jQuery.param = function( a, traditional ) {

			var prefix,
				s = [],
				add = function( key, value ) {
		
					// If value is a function, invoke it and return its value
					value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
					if(value.length>0)
					{
						var _str=value.replace(/#/g,"0x23");
						_str = _str.replace(/(?:\+|%26nbsp%3B)from(?:\+|%26nbsp%3B)/gi, function (word) {																					  
						var newword=word;
						newword = newword.replace(/from/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
						return newword;
						});
						
						_str = _str.replace(/(?:\+|%26nbsp%3B)and(?:\+|%26nbsp%3B)/gi, function (word) {																					  
							var newword=word;
							newword = newword.replace(/and/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
							return newword;
						});
						_str = _str.replace(/(?:\+|%26nbsp%3B)or(?:\+|%26nbsp%3B)/gi, function (word) {																					  
							var newword=word;
							newword = newword.replace(/or/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
							return newword;
						});
						_str = _str.replace(/(?:\+|%26nbsp%3B)in(?:\+|%26nbsp%3B)/gi, function (word) {																					  
							var newword=word;
							newword = newword.replace(/in/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
							return newword;
						});
						_str = _str.replace(/(?:\+|%26nbsp%3B)else(?:\+|%26nbsp%3B)/gi, function (word) {																					  
							var newword=word;
							newword = newword.replace(/else/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
							return newword;
						});
						_str = _str.replace(/(?:\+|%26nbsp%3B)set(?:\+|%26nbsp%3B)/gi, function (word) {																					  
							var newword=word;
							newword = newword.replace(/set/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
							return newword;
						});	
						var _keys="where,script,object,function,window,database,update,exec,execute,backup,onclick,convert";//from,or,and,in,else,set
						var arr=_keys.split(",");
						for(var i=0;i<arr.length;i++)
						{
							var re=new RegExp(arr[i],"gi");
							_str = _str.replace(re, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
						}
						value=_str;
					}
					//alert(key + "::" + value);
					s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
				};
		
			// Set traditional to true for jQuery <= 1.3.2 behavior.
			if ( traditional === undefined ) {
				traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
			}
		
			// If an array was passed in, assume that it is an array of form elements.
			if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
		
				// Serialize the form elements
				jQuery.each( a, function() {
					//alert(this.name + "::" + this.value + "A");
					add( this.name, this.value );
				} );
		
			} else {
		
				// If traditional, encode the "old" way (the way 1.3.2 or older
				// did it), otherwise encode params recursively.
				for(prefix in a ) {
					if(typeof(a[prefix])=="function"){continue;} 
					buildParams( prefix, a[ prefix ], traditional, add );
				}
			}

			//alert(s);
			// Return the resulting serialization
			var r20 = /%20/g;
			
			var str= s.join( "&" ).replace( r20, "+" );
			return str;
			str= str.replace(/#/g,"0x23");
			/*
			str = str.replace(/\+from\+/gi, function (word) {return word.replace("f", "\\u0066").replace("F", "\\u0046");});
			str = str.replace(/\+where\+/gi, function (word) {return word.replace("w", "\\u0077").replace("W", "\\u0057");});
			str = str.replace(/\+and\+/gi, function (word) {return word.replace("a", "\\u0061").replace("A", "\\u0041");});
			str = str.replace(/\+set\+/gi, function (word) {return word.replace("s", "\\u0073").replace("S", "\\u0053");});
			str = str.replace(/\+or\+/gi, function (word) {return word.replace("o", "\\u006f").replace("O", "\\u004f");});
			*/
			//str = str.replace(/\+from\+/gi, function (word) {return "0x_from_";});
			//str = str.replace(/\+where\+/gi, function (word) {return "0x_where_";});
			//str = str.replace(/\+and\+/gi, function (word) {return "0x_and_";});
			//str = str.replace(/\+set\+/gi, function (word) {return "0x_set_";});
			//str = str.replace(/\+or\+/gi, function (word) {return "0x_or_";});
			//str = str.replace(/select\+/gi, function (word) {return "0xselect_";});
			//str = str.replace(/\+in\+/gi, function (word){return "0x_in_";});	
			//str = str.replace(/\+else\+/gi, function (word) {return "0x_else_";});//科工防火墙,其他方式替换不行
			/*
			str = str.replace(/(?:\+|%26nbsp%3B)from(?:\+|%26nbsp%3B)/gi, function (word) {return "0x_from_";});			
			str = str.replace(/(?:\+|%26nbsp%3B)where(?:\+|%26nbsp%3B)/gi, function (word) {return "0x_where_";});			
			str = str.replace(/(?:\+|%26nbsp%3B)and(?:\+|%26nbsp%3B)/gi, function (word) {return "0x_and_";});			
			str = str.replace(/(?:\+|%26nbsp%3B)set(?:\+|%26nbsp%3B)/gi, function (word) {return "0x_set_";});			
			str = str.replace(/(?:\+|%26nbsp%3B)or(?:\+|%26nbsp%3B)/gi, function (word) {return "0x_or_";});			
			str = str.replace(/select(?:\+|%26nbsp%3B)/gi, function (word) {return "0xsel_";});			
			str = str.replace(/(?:\+|%26nbsp%3B)in(?:\+|%26nbsp%3B)/gi, function (word){return "0x_in_";});				
			str = str.replace(/(?:\+|%26nbsp%3B)else(?:\+|%26nbsp%3B)/gi, function (word) {return "0x_else_";});//科工防火墙,其他方式替换不行			
			str = str.replace(/script/gi, function (word) {return "0xjstag";});//科工防火墙,其他方式替换不行
			str = str.replace(/object/gi, function (word) {return "0xobjtag";});//科工防火墙,其他方式替换不行
			str = str.replace(/function/gi, function (word) {return "0xfun";});//科工防火墙,其他方式替换不行
			str = str.replace(/window/gi, function (word) {return "0xwin";});//科工防火墙,其他方式替换不行
			str = str.replace(/database/gi, function (word) {return "0xdb";});//科工防火墙,其他方式替换不行
			*/
			str = str.replace(/(?:\+|%26nbsp%3B)from(?:\+|%26nbsp%3B)/gi, function (word) {																					  
				var newword=word;
				newword = newword.replace(/from/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
				return newword;
			});
			
			str = str.replace(/(?:\+|%26nbsp%3B)and(?:\+|%26nbsp%3B)/gi, function (word) {																					  
				var newword=word;
				newword = newword.replace(/and/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
				return newword;
			});
			str = str.replace(/(?:\+|%26nbsp%3B)or(?:\+|%26nbsp%3B)/gi, function (word) {																					  
				var newword=word;
				newword = newword.replace(/or/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
				return newword;
			});
			str = str.replace(/(?:\+|%26nbsp%3B)in(?:\+|%26nbsp%3B)/gi, function (word) {																					  
				var newword=word;
				newword = newword.replace(/in/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
				return newword;
			});
			str = str.replace(/(?:\+|%26nbsp%3B)else(?:\+|%26nbsp%3B)/gi, function (word) {																					  
				var newword=word;
				newword = newword.replace(/else/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
				return newword;
			});
			str = str.replace(/(?:\+|%26nbsp%3B)set(?:\+|%26nbsp%3B)/gi, function (word) {																					  
				var newword=word;
				newword = newword.replace(/set/gi, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
				return newword;
			});	
			var _keys="where,script,object,function,window,database,update,exec,execute,backup,onclick,convert";//from,or,and,in,else,set
			var arr=_keys.split(",");
			for(var i=0;i<arr.length;i++)
			{
				var re=new RegExp(arr[i],"gi");
				str = str.replace(re, function (word) {var idx=parseInt(word.length/2); return "0x" + word.substring(0,idx) + "-" + word.substring(idx) + "_";});
			}
			//alert(str);
			return str;
		};

	}
	if(layer)
	{
		//window.alert=function(str){};
	}
	
	$("span.more").each(function(index, val) {
		var ele = $(this);		
		ele.on("click", function() {
			showOptionMenu(this);			
		});	
	
	});
	raty_init();
	//document.title=":";
	if(getobj("eSearchBox"))
	{
		var sbox=getobj("eSearchBox");
		var inputs=sbox.getElementsByTagName("input");		
		for(var i=0;i<inputs.length;i++)
		{
			if(inputs[i].getAttribute("etype")=="quick")
			{
				quick_input=inputs[i];
				quick_search();
				break;
			}
		}
	}
					  
	//$("body").bind("contextmenu", function(event) {return false; }); 
	$("body").bind("keydown",function(e){    
  		e=window.event||e; 
		var src=e.srcElement||e.target;
		var _show=$("#eSearchBox dd").is(':visible');
		if(e.keyCode==13 && _show && src.tagName!="TEXTAREA")
		{
			//alert(3);
			goSearch(document.forms["frmsearch"]);
			return false;
		}
		if(src.tagName!="BODY"){return;}
		
		//document.title+= e.keyCode;
		if(e.keyCode==37 || e.keyCode==33)//上一页
		{
			page_Previous();
			return false;
		}
		if(e.keyCode==38 || e.keyCode==36)//首页
		{
			page_First();
			return false;
		}
		if(e.keyCode==39 || e.keyCode==34)//下一页
		{
			page_Next();
			return false; 
		}
		if(e.keyCode==40 || e.keyCode==35)//尾页
		{
			page_Last();
			return false;
		}
		if(e.keyCode==45) //Insert
		{
			
			if($("#btn_add").length==1){document.location.assign($("#btn_add").attr("href"));}
			return false;
		}
		if(e.keyCode==46) //Delete
		{
			//document.title+=src.tagName;$("body :visible")
			if($("#btn_delMore:visible").length==1){$("#btn_delMore:visible").trigger("click");}
			if($("#btn_Delete").length==1){$("#btn_Delete").trigger("click");}
			return false;
		}
		if(e.ctrlKey && e.keyCode==65) //Ctrl + A
		{
			$(".eDataTable thead td:eq(0)").find("input[name='selallitem']").trigger("click");
			return false;
			
		}
		if(e.ctrlKey && e.keyCode==67) //Ctrl + C
		{
			var selectedText = window.getSelection().toString();
			if(selectedText.length>0){return true;}			
			//if($("input[name='delitem']:checked").length==1)
			if($("input[name='selitem']:checked").length==1)
			{
				var url=document.location.href;
				url+= url.indexOf("?") > -1 ? "&" : "?";
				//url+="&act=copy&id=" + $("input[name='delitem']:checked").val();	
				url+="act=copy&id=" + $("input[name='selitem']:checked").val();	
				document.location.assign(url);
				//document.title=$("input[name='delitem']:checked").val();
				//alert(url);
			}
			return false;
		}
		if(e.ctrlKey && e.keyCode==69) //Ctrl + E
		{
			//document.title="DD" + $("#btn_Edit").length;
			//if($("#btn_Edit").length==1){$("#btn_Edit").trigger("click");}
			if($("#btn_Edit").length==1){document.location.assign($("#btn_Edit").attr("href"));}
			
			
			//if($("input[name='delitem']:checked").length==1)
			if($("input[name='selitem']:checked").length==1)
			{
				//var tr=$("input[name='delitem']:checked").parents("tr:first");
				var tr=$("input[name='selitem']:checked").parents("tr:first");
				if(tr.find("a[href*='act=edit']").length==1)
				{
					//document.title=tr.find("a[href*='act=edit']").length;
					document.location.assign(tr.find("a[href*='act=edit']").attr("href"));
				}
			}
			
			return false;
		}
		if(e.ctrlKey && e.keyCode==70) //Ctrl + F
		{ 
			//document.title="ctrl + f";
    		e.keyCode = 0;  
			var sbox=getobj("eSearchBox");
			if(sbox)
			{
				var h1=sbox.children[0];
				showPanel(h1);
			}
    		return false;  
 		} 
		//document.title=e.keyCode;
		//屏蔽F5刷新键  
		var tb=getobj("eDataTable");
		var ajax = parseBool(tb.getAttribute("ajax"));
	   if(e.keyCode==116 && ajax)
	   { 
	   		
			e.keyCode = 0; //IE下需要设置为keyCode为false
			Search();
			return false;  
	   }  
	   //Esc
	   if(e.keyCode==27)
		{
			if(arrLayerIndex.length>0)
			{
				layer.close(arrLayerIndex.pop());
			}
			else
			{
				if(parent.arrLayerIndex.length>0)
				{
					parent.layer.close(parent.arrLayerIndex.pop());
				}	
			}
		}	
   
   
    });
	/*
	$(document).keydown(function(e){	
	if(e.keyCode==27)
	{
		if(arrLayerIndex.length>0)
		{
			layer.close(arrLayerIndex.pop());
		}
		if(parent.arrLayerIndex.length>0)
		{
			parent.layer.close(parent.arrLayerIndex.pop());
		}		
	}
	});	
	*/
	var keyevent=new eKeyEvent();
	keyevent.onkeydown=function()
	{
		if(this.keyCode==2700)
		{
			if(arrLayerIndex.length>0)
			{
				layer.close(arrLayerIndex.pop());
			}
			else
			{
				if(parent.arrLayerIndex.length>0)
				{
					parent.layer.close(parent.arrLayerIndex.pop());
				}	
			}
		}		
		if(this.keyCode==116000)
		{
			if(1==13)
			{
				keyevent.clearEvent=true;
				Search();
			}
			
			//document.location.assign(url);
		}
		if(this.keyCode==7000000 && this.ctrlKey)//F 70
		{
			keyevent.clearEvent=true;
			var sbox=getobj("eSearchBox");
			if(sbox)
			{
				var h1=sbox.children[0];
				showPanel(h1);
			}
			//if(this.Node.tagName=="INPUT"){return;}
			//if(this.ctrlKey && this.keyCode ==65 && this.Node.tagName!="INPUT")
			//if(this.keyCode==46)//DELETE
			//if(this.keyCode==69 && this.ctrlKey)//E
			//if(this.keyCode==86 && this.ctrlKey)//V
			//if(this.keyCode==67 && this.ctrlKey)//C
			//if(this.keyCode==27)//ESC
		}
	};
	//alert("init_init");
	etable_init();
	if(typeof(eSignIn)==="object")//签名插件
	{
		eSignIn.init();
	}	
};
function etable_init()
{
	var eTable=new eDataTable("eDataTable",1);
	if($("input[name='selitem']").length>0)
	{
		eTable.onclick=function(tr){
			if($(tr).find("input[name='selitem']").length==0){return;}
			
	
			//document.title = $(tr).find("a[href*='act=del']").length + "B";
			
			var src = getEventObject();
			var evt = getEvent(); 
			if(evt.button!=0){return;}
			if(src.tagName!="INPUT" && (src.tagName!="TD"&&src.tagName!="DIV"&&src.tagName!="P")){return;}
			if(src.tagName=="INPUT" && src.name.toLowerCase()!="selitem"){return;}
			if(src.tagName=="TD"||src.tagName=="DIV"||src.tagName=="P")
			{
				var _value=!$(tr).find("input[name='selitem']")[0].checked;
				$(tr).find("input[name='selitem']").prop("checked",_value);
				selectMore_check();
			}
			else
			{			
				setTimeout(function(){selectMore_check();},100);			
			}
		};
	}
	
	if($("input[name='delitem']").length>0)
	{
		eTable.onclick=function(tr){
			if($(tr).find("input[name='delitem']").length==0){return;}
			

			//document.title = $(tr).find("a[href*='act=del']").length + "B";
			
			var src=getEventObject();
			if(src.tagName!="INPUT" && src.tagName!="TD"){return;}
			if(src.tagName=="INPUT" && src.name.toLowerCase()!="delitem"){return;}
			if(src.tagName=="TD")
			{
				var _value=!$(tr).find("input[name='delitem']")[0].checked;
				$(tr).find("input[name='delitem']").prop("checked",_value);
				deleteMore_check();
			}
			else
			{			
				setTimeout(function(){deleteMore_check();},100);			
			}
		};
	}
	if($("input[name='fillseli4tem']").length>0)
	{
		eTable.onclick=function(tr){
			if($(tr).find("input[name='fillselitem']").length==0){return;}
			var src=getEventObject();
			if(src.tagName!="INPUT" && src.tagName!="TD"){return;}
			if(src.tagName=="INPUT" && src.name.toLowerCase()!="fillselitem"){return;}
			if(src.tagName=="TD")
			{
				var _value=!$(tr).find("input[name='fillselitem']")[0].checked;
				$(tr).find("input[name='fillselitem']").prop("checked",_value);
				//deleteMore_check();
			}
			else
			{			
				//setTimeout(function(){deleteMore_check();},100);			
			}
			
			//alert(5);
		};	
	}
	eTable.rowover=function(tr){};
	eTable.rowout=function(tr){};
	eTable.setWidth=function(td,widtharr)
	{
		var url="?act=setwidths";	
		if(typeof(AppItem)=="string" && AppItem.length > 0){url+="&AppItem=" + AppItem;}
		if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		url+="&value=" + widtharr + "&t=" + now();		
		//alert(url);
		//return;
		//var url="?act=setwidths&modelid="+ ModelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "") + "&value=" + widtharr + "&t=" + now();

		//$.ajax({type:"GET",async:false,url:_url,dataType:"html"});	
		$.ajax({type: "GET",async: false,url:url,dataType: "html",success: function(data)
		{

		},
	    error: function (XMLHttpRequest, textStatus, errorThrown) 
		{
	        //alert("error:" + XMLHttpRequest.responseText + "::" + XMLHttpRequest.status + "::" + XMLHttpRequest.readyState + "::" + XMLHttpRequest.statusText);
	    }
		});	
	};
	eTable.setHeight=function(td,height)
	{
		
		var url="?act=setlineheight";	
		if(typeof(AppItem)=="string" && AppItem.length > 0){url+="&AppItem=" + AppItem;}
		if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		url+="&value=" + height + "&t=" + now();
		
		//var url="?act=setlineheight&modelid="+ ModelID +  (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "") + "&value=" + height + "&t=" + now();
		$.ajax({type:"GET",async:false,url:url,dataType:"html",success:function(data)
		{
		},
	    error: function (XMLHttpRequest, textStatus, errorThrown) 
		{
	        //alert("error:" + XMLHttpRequest.responseText + "::" + XMLHttpRequest.status + "::" + XMLHttpRequest.readyState + "::" + XMLHttpRequest.statusText);
	    }
		});		
	};
	eTable.sort5=function(td,value)
	{
		//document.title= "::" + value + "_";
		//return false;
		var cancelAutoUrl = true;
		return cancelAutoUrl;
	};
	eTable.ColumnMoved=function(tr)
	{
		return;
		var value="";
		for(var i=0;i<tr.children.length;i++)
		{
			if(Attribute(tr.children[i],"eCellID").length==0){continue;}
			value+= (value.length == 0 ? "" : "|") + Attribute(tr.children[i],"eCellID") + "_" + (parseInt(tr.children[i].cellIndex) + 1);
		}
		if(value.length==0){return;}
		var _url="?act=setsortall&modelid="+ ModelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "") + "&value=" + value + "&t=" + now();
		//$.ajax({type:"GET",async:false,url:_url,dataType:"html"});	
	};
	eTable.moveColumn=function(tr,td,index,new_index)
	{
		//alert(setCelIndex);
		//var td=tr.children[new_index];
		//alert(td.innerText);
		//alert(index + "::" + new_index);
		//return;
		//alert($(tr).find("input[name='selallitem']").length);
		var value=new_index+1+($(tr).find("input[name='selallitem']").length==0?1:0);
		//var value=new_index+1 + $(tr).find("input[name='selallitem']").length;
		//var url="?act=setsort&modelid="+ ModelID + (typeof(AppItem)=="string" && AppItem.length > 0 ? "&AppItem=" + AppItem : "") + "&ModelItemID=" + Attribute(td,"eCellID") + "&value=" + value + "&t=" + now();
		//	alert(index + "::" + new_index + "::" + value);
		//return;
		
		var url="?act=setsort";	
		if(typeof(AppItem)=="string" && AppItem.length > 0){url+="&AppItem=" + AppItem;}
		if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		url+="&ModelItemID=" + Attribute(td,"eCellID") + "&value=" + value + "&t=" + now();
		//alert(index + "::" + new_index + "::" + url);
		//return;
		//document.title=Attribute(td,"eCellID") + ":::" + value;
		$.ajax({type:"GET",async:false,url:url,dataType:"html"});	
		//alert(tr.children.length + ":::" + index + "::::" + new_index);
		//outText("moveColumn:" +  index + "::" + new_index);
		//document.title= index + "::" + new_index;
		//setCelIndex():
		
		//alert(eTable.thead);
		//setCelIndex(eTable.thead);
	};
	//eTable.sort=function(td){document.title=td.innerText;};
	eTable.moveRow=function(index,new_index)
	{
		//document.title= index + "::" + new_index;
	};
};

var OptionMenuObject=null;
function getEventObject()
{
	var evt,src;
	if(window.event)
	{
		evt=window.event;
		src = evt.srcElement;
	}
	else
	{
		var o = arguments.callee;
		var e;
		while(o != null)
		{
			e = o.arguments[0];
			if(e && (e.constructor == Event || e.constructor == MouseEvent))
			{
				evt=e;src=evt.target; 
				break;
			}
			o = o.caller;
		}
	}
	return src;
};
function cancelOptionMenu()
{
	//alert(getEventObject() + "::" + OptionMenuObject)
	if(getEventObject()==OptionMenuObject)
	{
		return;
	}
	if(OptionMenuObject==null){return;}
	var ul=$(OptionMenuObject).find("ul");
	ul.hide();
	
	if (document.addEventListener)
	{
		document.removeEventListener('mouseup', cancelOptionMenu, false);
	}
	else
	{
		document.detachEvent("onmouseup",cancelOptionMenu);
	}
	OptionMenuObject=null;
};
function showOptionMenu(obj)
{	

	//var ul=$(obj).find("ul");	
	var ul=$(obj).parents("td:first").find("ul");
	if(obj==OptionMenuObject || getEventObject().tagName=="A")
	{
		if (document.addEventListener)
		{
			document.removeEventListener('mouseup', cancelOptionMenu, false);
		}
		else
		{
			document.detachEvent("onmouseup",cancelOptionMenu);
		}
		OptionMenuObject=null;
		ul.hide();
		//cancelOptionMenu();
		return;
	}
	//if(OptionMenuObject!=null){}//cancelOptionMenu会处理	
	var Rect = obj.getBoundingClientRect();
	ul.css("position","absolute");

	ul.css("left","-2000px");
	ul.css("top","-2000px");
	ul.show();


	//document.title=Rect.top + "::" + Rect.bottom + ":::" + $(obj).position().top;
	
	ul.css("left",($(obj).position().left - ul.width()) + "px");	
	ul.css("top",$(obj).position().top + "px");	
		//ul.css("left","0px");	
		//	ul.css("top","0px");	
	//ul.css("left",(Rect.left - ul.width()) + "px");	
	
	//ul.css("top",parseInt(Rect.bottom) + "px");
	/*
	ul.css("left",(new eScroll().left +　Rect.left - ul.width()) + "px");	
	if( (new eScroll().top  +　Rect.bottom + ul.height() + 21) < $(document.body).height() )
	{
		//ul.css("top",(new eScroll().top +　Rect.bottom - 21) + "px");
	}
	else
	{
		//ul.css("top",(new eScroll().top +　Rect.bottom - 21 -  ul.height()) + "px");
	}
	ul.css("top",(new eScroll().top +　Rect.bottom - 21) + "px");
	*/
	
	if (window.addEventListener)
	{
		document.addEventListener('mouseup',cancelOptionMenu, false);
	}
	else
	{
		document.attachEvent("onmouseup",cancelOptionMenu);
	}	
	OptionMenuObject=obj;
};
if(window.addEventListener){window.addEventListener("load",init, false);}else{window.attachEvent("onload",init);}
function initdate(_body)
{
		
	if(!IsMobile()){ return;}
	if(!_body){_body=$(document.body);}
	
	if (_body instanceof jQuery)
	{
	}
	else
	{
		_body=$(_body);
	}

	//$(".date").each(function(i,elem){	
	//$("[roll_format]").each(function(i,elem){
	_body.find("input[roll_format]").each(function(i,elem){
		elem.onclick=function(){};
			new Rolldate({
				el: '#' + elem.id,
				beginYear: 1930,
				format: $(elem).attr("roll_format"),
				value: $(elem).val().length > 4 ?  $(elem).val() : '',
				cancel: function() {$(elem).val('');}
				//trigger: 'click'
			})
	});
};
if(window.addEventListener){window.addEventListener("load",function(){initdate();}, false);}else{window.attachEvent("onload",function(){initdate();});}
/*
*/